- See list of branches
- Create a new branch
- Rename a branch
- Delete a branch
- Switch branches
- Merge branches
See list of branches
$ git branch
Adding the -r option will list the remote tracking branches as well. Adding the -a option will show both remote and local branches.
Create a new branch
$ git branch <branchname>
Rename a branch
$ git branch -m <oldbranch> <newbranch>
Delete a 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. You can specify -D however to force delete it irrespective of its merge status.
Switch branches
$ git checkout <branch>
This will allow you to check out and switch to your desired branch.
Adding the -b option will cause a new branch to be created and then checked out.
Merge branches
$ git merge <branch>
Adding the --no-ff option will cause a Git merge 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.