Say that someone created a branch xyz. How do I pull the branch xyz from the remote server (e.g. GitHub) and merge it into an existing branch xyz in my local repo?
The answer to
Push branches to Git gives me the error "! [rejected]" and mentions "non fast forward".
That’s because Git can’t merge the changes from the branches into your current master. Let’s say you’ve checked out branch
master, and you want to merge in the remote branchother-branch. When you do this:Git is basically doing this:
That is, a
pullis just afetchfollowed by amerge. However, whenpull-ing, Git will only mergeother-branchif it can perform a fast-forward merge. A fast-forward merge is a merge in which the head of the branch you are trying to merge into is a direct descendent of the head of the branch you want to merge. For example, if you have this history tree, then mergingother-branchwould result in a fast-forward merge:However, this would not be a fast-forward merge:
To solve your problem, first fetch the remote branch:
Then merge it into your current branch (I’ll assume that’s
master), and fix any merge conflicts: