Reputation: 625
In the root of my local repo I switch from a feature branch back to develop
:
$ git checkout develop
Switched to branch 'develop'
Your branch is up to date with 'origin/develop'.
Please notice the last info message there: Your branch is up to date with 'origin/develop'. To me, that means that my branch is totally caught up to the HEAD
of origin/develop
and that there are no new changes to pull.
But when I do...
$ git pull
remote: Counting objects: 10, done.
Unpacking objects: 100% (10/10), done.
From ssh://my-code-commit/v1/repos/myproj
5840bf6..cc91737 develop -> origin/develop
Updating 5840bf6..cc91737
Fast-forward
src/main/java/com/me/myapp/processor/Fizzbuzz.java | 39 +++++++++++++++++++++++++++++++++++++++
src/main/java/com/me/myapp/processor/Foobar.java | 6 ++----
src/main/resources/META-INF/spring/routes/FlimFlam.xml | 21 +++++++++++++++++++++
Whaaaaaat?! How could this be?! How could there be remote changes to pull if my local develop
is "up to date with origin/develop
"?!
Is this a misleading message or am I fundamentally misunderstanding what git means when it says I'm up to date?
Upvotes: 6
Views: 5113
Reputation: 643
git pull
actually means git fetch && git merge [upstream]
So, this scenario, considering the output means that at the moment you checked-out, your local repo had 5840bf6
as HEAD. This usually happens when you check out to a branch matching another from Origin.
So, when you pull
, your local repo updates its references, finds out that there are new commits to merge and then it updates to cc91737
.
TL;DR: "Your branch is up to date with 'origin/develop'." actually means "Your branch is up to date with 'origin/develop'... AFAIK"
Upvotes: 0
Reputation: 388023
Usually, there are three different kinds of branches you have to consider:
The work you do is usually done on local branches. These are the normal branches that you create and check out. E.g. when you do git branch foo
or git checkout -b foo
, you create a local branch. Local branches are the easiest to understand.
Now, when talking about a remote repository, you usually don’t work with that directly. So instead, it has some local state itself. For example, when you push to a remote master
branch, then that remote repository has a master
branch on its own. That is the branch in the remote repository.
When you add a repository as a remote to your local repository, then Git will use remote branches to represent the state the remote repository is in. When you run git fetch
, Git will fetch the branch information from the remote and update its remote branches. Remote branches are of the pattern <remote-name>/<branch-name>
.
So if a remote repository origin
has a local branch master
, then when fetching that remote, your local repository will create a remote branch origin/master
. That remote branch exists within your local repository and represent the state of the master
branch in the remote.
Now, when you also have a local branch master
, you can set up that branch to track the remote branch. That means that you will link master
and origin/master
so that pushing and pulling knows exactly which remote and which branch on the remote they have to interact with; and it will also give you that information when you switch to the branch.
However, it’s important to keep in mind that Git, being a distributed version control system where almost everything is executed locally, will only look at the remote branch when checking the state of your local branch. It will not automatically connect to the remote repository to check its local state of the branch.
So when Git says “Your branch is up to date with 'origin/master'” then what it means is “Your local branch and the remote branch that exists locally currently point at the same commit but the remote branch could possibly be stale”. To fix that, you will first have to run git fetch
to update the remote branches in your local repository so that they reflect the new current state of the remote repository.
Upvotes: 8