6

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?

2 Answers 2

8

Usually, there are three different kinds of branches you have to consider:

  • A branch in a remote repository
  • A remote branch in your local repository
  • A local branch in your local repository

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.

2
  • So the message should be changed, as I've had this bite me.. I did a checkout of develop, made my changes (after skipping doing a pull, as it said I had the latest, or I thought that it did, because sometimes it says "your branch is X commits behind"), and then made my changes and pushed with conflicts and had to resolve them... It should either check the actual remote (why wouldn't it do that if it has a remote configured??), or should shut the heck up about it... Or instead say: "you might want to do a fetch/pull, as I'm clueless if you are up to date with the remote origin/" Commented Mar 13 at 16:34
  • Btw: it will only say you are X commits behind, if you do a 'fetch' to find that information out, otherwise it will say you are up to date. IMO this is one of the things that drives me nuts about git, but the message that explicitly says it is up to date with ORIGIN/branchName, is SO misleading as to be criminal... Nothing like giving someone a warm fuzzy that they are good to go, when you actually have no knowledge about ORIGIN/* and would need a fetch to know.. It is like have a fake doctor be an expert witness in a trial... Oh, I'm going off the status from 2 weeks ago and you're good Commented Mar 13 at 16:42
0

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"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.