Git branches

Branches management

List branches

git branch
  • -a argument includes remote branches

Switch branches

To move to another branch

git checkout <new_branch>

To create a branch and move to created branch:

git checkout -b <new-branch>

Rename branches

If you want to rename a branch while pointed to any branch, do:

git branch -m <oldname> <newname>

If you want to rename the current branch, you can do:

git branch -m <newname>

From StackOverflow

Removing branches

To remove a merged local branch:

git branch -d <branch_name>

In case branch was not merged locally, force deletion with -D

git branch -D <branch_name>

To delete a remote branch:

git push origin --delete <remote_branch_name>

From this cheatsheet