Skip to main content
  1. Learn center
  2. Software Development
  3. Guides
  4. Git tutorial
  5. Git commands & settings
  6. Git branch commands
GuidesSoftware DevelopmentBacklog
Git

Project and code management together.

Git branch commands


Show list of branches

$ git branch

The current branch will be highlighted in green and marked with an asterisk.

Adding the -r option will also list the remote tracking branches. Adding the -a option will show both remote and local branches.

Create branch

$ git branch <branchname>

See:

Rename branch

$ git branch -m <oldbranch> <newbranch>

Delete branch

$ git branch -d <branchname>

If the branch has not been fully merged with an upstream branch, or in HEAD if there is no upstream, Git will not allow you to delete the branch. However, you can specify -D to force delete it irrespective of its merge status.

See:

Switch branches

$ git checkout <branch>

This will allow you to check out and switch to your desired branch.

Adding the -b option will create a new branch and switch to it.

See:

Merge branches

$ git merge <branch>

Adding the --no-ff option will cause a git merge command to always create a merge commit instead of fast-forwarding. This is useful because it allows you to retain the historical information of a branch before it was merged.

When you add the --squash option, Git creates a single commit that represents the merged changes instead of creating a merge commit. This commit contains the changes from the merged branch but doesn't contain any of the information associated with the merged branch or the merge process itself.

See:

Subscribe to our newsletter

Learn with Nulab to bring your best ideas to life