Git Branching
Check all locally available branches
$ git branchMake a new branch & Switch to new branch
$ git branch <name of the branch> # e.g. git branch dev1
$ git checkout <name of the branch> # e.g. git checkout dev1You can do the above 2 steps in a single line
$ git checkout -b <name of the branch> # e.g. git checkout -b dev1Delete a branch
$ git branch -d <name of the branch> # e.g. git branch -d dev1Delete a branch locally and remotely
Locally
Two options to delete a local branch
Option 1:
$ git checkout main # first switch to main branch from the branch you want to delete
$ git branch -d <name of the branch to delete>Option 2:
If you get run into an error such as the following
error: The branch 'feature' is not fully merged. If you are sure you want to delete it, run 'git branch -D feature'.
then do
Please note, the above command will discard all the unmerged changes
Remotely
To delete remote branch
Merging two branches:
View local and remote branches
To view all local and remote branches
To view only remote branches
Pull remote branches to local repo
Let's say we have "dev2" branch on our remote repo, but not locally. We can pull this branch locally and start working on it
Set up default branch as main/master
Last updated