Git merge
Internal
Overview
git checkout <base-branch> git merge <head-branch>
By default, merge creates a merge commit.
However, if the branch we're merging from contains only extra commits, and the branch we are on does not contain commits that are not in the branch we're merging from, git merge will automatically fast forward without specifying anything. This is the case when, after a git fetch
, the origin branch advances with new commits and our local tracking branch is clean. In this case we can fast forward with:
git checkout <tracking-branch> git merge origin/<tracking-branch>
Options
--no-ff
Create a merge commit even when the merge resolves as a fast-forward. This is the default behaviour when merging an annotated tag. This is also the default behavior when merging GitHub pull requests with "Create a merge commit" option.
Troubleshooting
No remote for the current branch
There are situations when a previously well behaving local branch with a correctly set remote-tracking branch fails on merge after a fetch:
git merge
fatal: No remote for the current branch.