Skip to main content

Main git command for working with branches.

# To list all branches (local and remote; the current branch is highlighted by '*'):
git branch --all

# To list which branches include a specific Git commit in their history:
git branch --all --contains <commit_hash>

# To show the name of the current branch:
git branch --show-current

# To create new branch based on the current commit:
git branch <branch_name>

# To create new branch based on a specific commit:
git branch <branch_name> <commit_hash>

# To rename a branch (must not have it checked out to do this):
git branch -m <old_branch_name> <new_branch_name>

# To delete a local branch (must not have it checked out to do this):
git branch -d <branch_name>

# To delete a remote branch:
git push <remote_name> --delete <remote_branch_name>