Show list of branches
$ git branch
The current branch will be highlighted in green and marked with an asterisk.
-r option will also list the remote tracking branches. Adding the
-a option will show both remote and local branches.
$ git branch <branchname>
$ git branch -m <oldbranch> <newbranch>
$ 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.
$ git checkout <branch>
This will allow you to check out and switch to your desired branch.
-b option will create a new branch and switch to it.
$ git merge <branch>
--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.