Git - Branch


This page talks about Branch management in Git.

For Git, a branch is:

Example of commit log (or log):

CA1--CA2--CA3 <-- Branch A (last commit CA3)
 C1--C2--C3 <-- master (last commit C3)
         CB1--CB2 <-- Branch B (last commit CB2)

What is a Head ?

The term “branch head” (or just “head”) reference to the most recent commit on a branch.

In the example above, the branch head of:

  • the branch A is the commit CA3
  • the branch B is the commit CB2

If you are not on a last commit, you are no more on a branch, you are in a detached mode


The identification of branch may have a / or a space


  • With a space, , you're referring to a remote branch (branch on a remote machine over the network)
remote name

A branch name is just a ref (A name attached to a commit sha).



A local branch is a branch that exists only on your computer.

A local tracking branch is a local branch that is tracking another branch.

Remote Tracking


See remote branch




Usage / Strategy

Creating two features branch:

  • heart glasses
  • cowboy hat

Branches Git

Each feature is added back to the master individually. So if glasses are finished before the cowboy hat, no problem.

More see Git - Workflow (Branching Strategy)

Example of lifecycle

Example of workflow

# Create a feature branch
git checkout -b feature-myfeature develop
# Merge your work
git checkout develop
git merge --no-ff feature-myfeature
# Delete your branch
git branch -d feature-myfeature
# Integrate your work into the master repo
git push origin develop

Github Branch


The git docs/git-branch.html command lists, creates, or delete branches.

Working / Current

The working or current branch is the branch actually in the working tree.

More… see current




Keeping your branch current with a parent branch (master for instance)

When merging two branches, Git check the commit sha of the branche ref and add the missing's one accordingly.


Update the master / main branch

  • Switch to the local copy of master
git checkout master
git fetch origin
:: git fetch upstream
git merge origin/master
:: git merge usptream/master

Update the branch (Rebase)

  • Go to the branch (ie checkout the files for this branch from the repository)
git checkout branchName
git rebase master

Ctrl + T shortcut on IDEA


fetch all the remote branches from origin

git fetch origin


git branch --remotes
# or
git branch -r


Check out an existing branch

Remote Checkout

cd path/to/git/repository
git fetch origin
git checkout brancheName
git checkout brancheName
Switched to a new branch 'brancheName'
Branch 'brancheName' set up to track remote branch 'brancheName' from 'origin'.

The branch is now a remote tracking branch (a local branch that tracks the remote branch


From a tag

See Git - Tag


  • Switch does not require a clean index and working tree (i.e. no differences compared to HEAD)
  • The working tree and the index are updated to match the branch.
  • All new commits are added to the tip of this branch.
git switch


  • After working in the wrong branch, switching to the correct branch would be done using:
git switch -m mytopic

where m performs a three-way merge

In case of modification



git stash # keep the modification in a stash branch
git pull # get the last one
git stash pop # Destash the modification

Revert to head

Revert to the head of the upstream/master branch

git reset --hard upstream/master


See What is a Git Checkout?

git checkout branchName
Switched to branch 'branchName'


When you want to share a branch with the world, you need to push it up to a remote that you have write access to.

git push <remote> <branch>


  • delete branch locally
git branch -d branchName
  • delete a branch remotely with push
git push origin --delete branchName

Documentation / Reference

Discover More
Card Puncher Data Processing
Android - Getting Started

See See Run Apps on a Hardware Device Enable USB debugging in the device system settings, under Settings > Developer...

is a content-addressable file system used to track directory tree content (as defined by its creator Linux Torvald) It's not a version control...
Git - Clone

git clone creates a clone known as local repository from a remote repository. cloning in git means: downloading the remote repository into a newly created directory setting for each downloaded branch...
Git - Current / working / HEAD / active branch

The current or active branch is: the branch checked out actually in the working tree The current branch is also known as the HEAD branch (in uppercase) that represents the last commit known...
Git - Detached HEAD

What means a DETACHED HEAD in git
Git - Feature Branch

A branch that was created to add a feature. Create a branch off of develop called “feature-[feature name]”, work and commit into that branch.
Git - Head (Head Branch | Branch Head)

The head is the last commit of a branch. while the HEAD (in uppercase) is the head of the current branch (active branch). headHEADcurrent branch page In the example below, the branch head of: ...
Git - Local branch

A local branch is a branch that exists only on your computer. tracking branch There are two types of local branches: non-tracking local branches. They are not associated with any other branch....
Git - Master branch

master is the default name for a starting branch when you run git init
Git - Merge

Merge is a git merge tool that is designed to integrate changes from one branch into another branch It joins two or more branch together (ie development histories) The pull command is a wrapper that...

Share this page:
Follow us:
Task Runner