Reputation: 149
My team mate updated his branch feature1
on remote while I was working on feature2
.
Now when I do $ git remote show origin
, it shows -
Local refs configured for 'git push':
feature1 pushes to feature1 (local out of date)
I am currently checked out on branch feature2
, and I tried all the commands below, but the state of feature1
doesn't change to (up to date)
. (All commands execute without any errors)
$ git fetch origin
$ git fetch --all
$ git fetch origin feature2
Why does this happen? What am I missing?
Upvotes: 0
Views: 544
Reputation: 489828
After using git fetch
to obtain new commits from some other Git, you must choose how to combine those new commits with any of your own existing commits.
There are two main ways to combine commits:
git merge
git rebase
These are very different actions in some cases. In other cases—including specifically the case where all of your existing commits just came from that other Git in the first place, and you never make any of your own commits, and the person managing the other Git behaves well—they do exactly the same thing so that it won't matter which one you do (unless the second command fails; see below).
My own process is generally: run git fetch
, inspect what happened, then choose which of git merge
or git rebase
I want to do, if I want to do any of them yet. Then, I do the second command that I'd like to do based on the results of this inspection, or I hold off entirely based on the results of this inspection.
If you are sure about which second command you'd like to use, you can use git pull
, which runs git fetch
, then runs one of these other two Git commands. You choose in advance, before seeing what git fetch
brings, which other Git command to run. The default second command is git merge
, so if you're absolutely sure, in advance, that you want to git fetch
and then git merge
, you can run git pull
. If you're absolutely sure, in advance, that you want to run git rebase
second, you can run git pull --rebase
.
Note that both git merge
and git rebase
can fail, and leave you with a mess to clean up. If you run git pull
and its second command fails, you're still in the middle of whichever second command you chose to have git pull
run. You'll still need to clean up the mess. You can wait until this actually happens to learn how to clean it up, but remember that the way to clean it up depends on which second command you chose! I like to avoid git pull
so that I know which second command I used via the fact that I typed it in. :-)
Upvotes: 1
Reputation: 10094
git fetch just download objects and refs from another repository. To get the changes into your branch you have to do a git merge.
To do both things in one step you can use git pull
In your case:
git merge origin/feature2
Upvotes: 1