Branches #
Listing branches #
The command
git branch
allows you to list all local branches (for the current repository).
Creating a branch #
To create a new branch, run
git branch <branchName>
Then you can switch to this branch with
git checkout <branchName>
Alternatively, you can perform both operations with a single command:
git checkout -b <branchName>
Deleting a branch #
You can delete a (local) branch other than the current branch with
git branch -d <branchName>
Merging a branch #
To merge a branch <branchToMerge>
into a branch <receivingBranch>
, switch first to the receiving branch:
git checkout <receivingBranch>
Then run
git merge <branchToMerge>
If possible, a fast-forward merge will be performed.
Otherwise a regular merge will be attempted. If this cannot be done (due to merge conflicts), then you will be asked to fix the merge conflicts. After fixing the conflicts, you can finalize the merge with
git commit