Git merge: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
 
(9 intermediate revisions by the same user not shown)
Line 4: Line 4:


=Overview=
=Overview=
<syntaxhighlight lang='bash'>
git checkout <base-branch>
git merge <head-branch>|<tag>
</syntaxhighlight>


  git checkout <''base-branch''>
By default, merge creates a merge commit.
  git merge <''head-branch''>
 
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 <code>git fetch</code>, 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=
=Options=
Line 13: Line 21:


Create a merge commit [[Git_Concepts#Forcing_No_Fast-Forward|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 "[[GitHub Procedures#Create_a_Merge_Commit|Create a merge commit]]" option.
Create a merge commit [[Git_Concepts#Forcing_No_Fast-Forward|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 "[[GitHub Procedures#Create_a_Merge_Commit|Create a merge commit]]" option.
=Troubleshooting=
If 'git merge' produces this error message:
<syntaxhighlight lang='text'>
fatal: No remote for the current branch.
</syntaxhighlight>
it's probably because the local branch has not been linked to its remote-tracking branch. Fix with: {{Internal|Git_branch#Link_the_Local_Branch_to_its_Tracking_Branch|Link the Local Branch to its Tracking Branch}}

Latest revision as of 19:55, 5 September 2022

Internal

Overview

git checkout <base-branch>
git merge <head-branch>|<tag>

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

If 'git merge' produces this error message:

fatal: No remote for the current branch.

it's probably because the local branch has not been linked to its remote-tracking branch. Fix with:

Link the Local Branch to its Tracking Branch