ApX logoApX logo
ModelsCalculatorHardwareCoursesPricing
ApX logoApX logo
ModelsCalculatorHardwareCoursesPricing

All Courses

Getting Started with Git
Chapter 1: Introduction to Version Control and Git
What is Version Control?
Why Use Version Control Systems (VCS)?
Centralized vs Distributed VCS
Introducing Git: A Distributed Approach
Core Git Concepts: Repository, Commit, Branch
Installing Git on Windows
Installing Git on macOS
Installing Git on Linux
Initial Git Configuration (user.name, user.email)
Getting Help with Git Commands
Quiz for Chapter 1
Chapter 2: Your First Git Repository
Creating a New Repository with git init
The Git Workflow: Modified, Staged, Committed
Checking the Status of Your Files (git status)
Adding Files to the Staging Area (git add)
Committing Changes (git commit)
Writing Good Commit Messages
Viewing Commit History (git log)
Understanding .gitignore Files
Hands-on Practical: Initialize and Make First Commit
Quiz for Chapter 2
Chapter 3: Viewing History and Undoing Changes
Comparing Changes (git diff)
Viewing Changes Between Commits
Viewing Staged vs Unstaged Changes
Unstaging Files (git reset HEAD )
Amending the Last Commit (git commit --amend)
Reverting Commits (git revert)
Removing Files from Git (git rm)
Moving or Renaming Files (git mv)
Practice: Inspecting and Modifying History
Quiz for Chapter 3
Chapter 4: Branching and Merging Basics
What Are Branches in Git?
Creating a New Branch (git branch)
Switching Between Branches (git checkout or git switch)
Listing Branches
Making Commits on a Branch
Merging Branches (git merge)
Understanding Fast-Forward Merges
Handling Merge Conflicts
Deleting Branches (git branch -d)
Hands-on Practical: Branching and Merging Workflow
Quiz for Chapter 4
Chapter 5: Working with Remote Repositories
Introduction to Remote Repositories
Common Hosting Platforms (GitHub, GitLab, Bitbucket)
Adding a Remote Repository (git remote add)
Viewing Remote Repositories (git remote -v)
Cloning an Existing Repository (git clone)
Pushing Changes to a Remote (git push)
Fetching Changes from a Remote (git fetch)
Pulling Changes from a Remote (git pull)
Understanding origin and upstream
Practice: Cloning, Pushing, and Pulling
Quiz for Chapter 5

Creating a New Branch (git branch)

Managing different tasks simultaneously, like developing a new feature while fixing a separate bug, requires a way to isolate these lines of work. Git provides this isolation through branches. Branches are movable bookmarks or pointers in your project's history. When you want to start a new line of development, you create a new branch.

The command to create a new branch is git branch followed by the name you want to give the branch.

git branch <branch-name>

For example, if you are about to start working on a new website header, you might create a branch named update-header:

git branch update-header

What happens when you run this command? Git creates a new pointer (named update-header in this case) that points to the exact same commit you are currently on (where the HEAD pointer is). It's important to understand that this command only creates the branch; it does not switch you to it. Your working directory files remain unchanged, and you are still on the same branch you were on before running the command.

Imagine your project history looks like this, where main is your primary branch and HEAD indicates your current position:

Your repository state before creating a new branch. HEAD points to main, which points to the latest commit C3.

Now, if you run git branch update-header, the state becomes:

After running git branch update-header. A new pointer update-header is created, pointing to the same commit C3 as main. HEAD still points to main.

Notice that a new pointer, update-header, now exists and points to commit C3. However, HEAD still points to main, indicating that main is still your active branch.

Branch Naming Conventions

While Git allows almost any name for a branch (except those containing spaces or certain special characters), it's good practice to use descriptive names. Common conventions include:

  • Using hyphens to separate words (e.g., fix-login-bug).
  • Using prefixes like feature/, bugfix/, or hotfix/ to categorize branches (e.g., feature/user-profiles, bugfix/issue-451).

These conventions make it easier for you and your collaborators to understand the purpose of different branches just by looking at their names.

Creating a branch sets the stage for isolated development. The next step, which we'll cover in the following section, is actually switching to your new branch to start working on it.

  • Git Reference Manual - git-branch, Git Development Community, Current - The official command reference for git branch, detailing its usage and various options.
  • Pro Git, Chapter 3: Git Branching - Branches in a Nutshell, Scott Chacon and Ben Straub, 2014 (Apress) - A foundational chapter explaining Git branches as pointers and how they are created, with helpful diagrams.
  • Git Branching, Atlassian, Current (Atlassian) - A practical guide to understanding and creating Git branches, offering a clear explanation suitable for new users.

© 2026 ApX Machine Learning