Advertisement

List Branches

Show all local branches.

git branch

Show all branches including remote:

git branch -a

Show remote branches only:

git branch -r

Create a New Branch

Create a new branch without switching to it.

git branch <branch-name>

Create and switch to new branch:

git checkout -b <branch-name>

Using the newer switch command:

git switch -c <branch-name>

Switch Branches

Switch to an existing branch.

git checkout <branch-name>

Using the newer switch command:

git switch <branch-name>

Switch to previous branch:

git checkout -

Rename a Branch

Rename the current branch.

git branch -m <new-name>

Rename a specific branch:

git branch -m <old-name> <new-name>

Delete a Branch

Delete a merged branch.

git branch -d <branch-name>

Force delete an unmerged branch:

git branch -D <branch-name>

Delete a remote branch:

git push origin --delete <branch-name>

Merge Branches

Merge a branch into the current branch.

git merge <branch-name>

Merge without fast-forward:

git merge --no-ff <branch-name>

Abort a merge in progress:

git merge --abort
Advertisement

Rebase

Rebase current branch onto another branch.

git rebase <branch-name>

Interactive rebase for last N commits:

git rebase -i HEAD~3

Continue rebase after resolving conflicts:

git rebase --continue

Abort rebase:

git rebase --abort

Compare Branches

Show commits in branch1 not in branch2.

git log branch1..branch2

Show differences between branches:

git diff branch1..branch2

Track Remote Branch

Create local branch tracking remote branch.

git checkout --track origin/<branch-name>

Set upstream for current branch:

git branch -u origin/<branch-name>

Show Branch Information

Show branches with last commit.

git branch -v

Show merged branches:

git branch --merged

Show unmerged branches:

git branch --no-merged

Checkout Remote Branch

Create local branch from remote branch.

git checkout -b <local-branch> origin/<remote-branch>
Last updated: January 2026
Advertisement