Branches
Create local branch
To create a new branch and switch to it at the same time, you can run
This is shortcut to
To be able to make commits into GitHub (or whichever Git hosting service you use) you need to first push the current branch and set the remote as upstream:
Add local branch from remote branch
If your repository already has a remote branch that you want to work on locally, you can add it to your local repository by running
or on older verions of Git:
Switch between branches
To switch between your branches and your master
branch, you can use the
and
Merge branches
Before merging branches, make sure you are on the receiving branch (usually master
) by running
After that, you can merge your desired branch <merged-branch>
to <receiving-branch>
by running
Delete branches
Delete local branch
Once you've finished working on a branch and have merged it into the main code base, you're free to delete the branch without losing any history:
However, if the branch hasn't been merged, the above command will output an error message warning you that the branch is not fully merged.
If you really want to delete the branch, you can use the -D
flag:
This deletes the branch regardless of its status and without warnings, so use it judiciously.