why does it say “Your branch is ahead of origin/master by 857 commits” when I need to *pull* origin master

Firstly, I’m aware of a number of similarly worded questions, eg:

  • How can I find the location of origin/master in git, and how do I change it?
  • git: Your branch is Ahead by X commits
  • Git: Branch is ahead by X commits. Doesn't help doing git pull
  • pull-only repo's 'git status' saying the branch is ahead of origin/master. Why?

None of them (AFAICT) has an answer that matches my version of this question.

  • How can I label my current git branch as ok then continue
  • Git - why are double dashes needed when running a command on a deleted file?
  • On git pull, “unable to resolve reference” and “Undefined error: 0”
  • Git Submodules: Is it possible to have more than one URL for each?
  • How can I modify the path to git repo in RStudio (.git in higher lever directory than .Rproj)?
  • How import old repo files in new git server
  • My situation is:

    $ git status
    # On branch stable
    nothing to commit (working directory clean)
    $ git checkout master
    Switched to branch 'master'
    Your branch is ahead of 'origin/master' by 857 commits.
    

    In the existing questions the accepted and upvoted answers mostly concur that it means literally what it says… I’m ahead and I need to push my new commits to origin/master.

    I know that actually the opposite situation is true, that my local master branch is behind the remote origin/master and actually I need to git pull origin master before doing some work on it locally. (or possibly just git fetch origin ?)

    My question is… is there some reason for the message to be worded Your branch is ahead of 'origin/master' by 857 commits. such that it literally makes sense?

    Because the way I understand it at the moment the meaning is the opposite of what the message says (‘my branch’ is behind origin/master).

    Or does it really mean: “The HEAD of the remote master branch is ahead of your local origin/master tracking branch” ?

    update
    FWIW I am working in a team of half a dozen other developers. We all pull, commit and push etc many times a day without problem. I don’t have a bug here… I’m just trying to understand why Git words its message this way – whether the wording itself is badly chosen, or if there’s some underlying concept of Git that causes them to word it this way and which I’m not understanding properly.

    more info
    here is what I guess may be the relevant part of output from git config -l

    remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
    remote.origin.url=https://code.google.com/a/google.com/p/xxxxx/
    branch.master.remote=origin
    branch.master.merge=refs/heads/master
    branch.master.mergeoptions=--no-ff
    

  • How can I 'git merge' a new file based on a tracked file of a different name?
  • Apply merge rules from .gitattributes file to git rebase calls
  • .gitattributes not making a difference, trying to skip files when using git difftool
  • How to include a parent Spring project (using Git submodule)?
  • git flow branches have diverged
  • git: delete remote branch from mirror tree
  • 4 Solutions collect form web for “why does it say “Your branch is ahead of origin/master by 857 commits” when I need to *pull* origin master”

    You are over thinking this. The message isn’t saying the remote is behind. It’s saying your local repository’s recorded commit for ‘origin/master’ is. At no point in generating that message did git communicate with a remote. It simply looked into the .git directory, and returned the contents of .git/refs/remotes/origin/master. Try it yourself. Both of these commands should return the same thing from the top-level of the repository:

    cat .git/refs/remotes/origin/master
    git rev-parse origin/master
    

    The second command is simply a plumbing command for finding the ‘origin/master’ pointer. You could replace ‘origin/master’ with any branch to get the most recent commit on that branch.

    That message is telling you is that your local ‘master’ is ahead of the commit returned by ‘git rev-parse origin/master’ by 857 commits. How did this situation arise? I can’t say exactly, but I’d put considerable money on you accidentally merging a different branch into ‘master’. Every time I’ve seen this problem, it’s a bad merge from user error.

    First, issue git fetch origin to make sure that ‘origin/master’ pointer is up-to-date. Then, study your git log. Look for something recent you don’t expect. Download a program like tig or use gitk to get a visual graph of your commit history. It’s a good bet you accidentally issued git pull stable while checked out on ‘master’. Or something similar.

    git rebase -p

    It will say First, rewinding head to replay your work on top of it... and you’ll be all set, because there’s no work to replay.

    I had this question too. I searched a bit and found out that, we occasionally run ‘git pull upstream master’ to fetch the latest changes from upstream master to our local master which is a forked branch. However these updated changes are not pushed to our remote master yet. Hence the message says ‘our local is x commits ahead of remote master’. Before proceeding with new code or modification in forked branch environment, it’s better to run the following commands

    git checkout master_branch;
    git pull upstream master;
    git push

    In the end, the Actual solution for the question to correct the problem:

    It was because it needed a git push, after a merge. This just happened to me too, same error message. Andy magoon was right also, because when I did the push, I see a clean slate now, with no bytes having been pushed. However, rebasing is not usually the best course.

        $ git status ./
    On branch master-blah1
    Your branch is ahead of 'origin/master-blah1' by 869 commits.
      (use "git push" to publish your local commits)
    nothing to commit, working directory clean
    
    
        $ git push
        Counting objects: 7, done.
        Delta compression using up to 48 threads.
        Compressing objects: 100% (7/7), done.
        Writing objects: 100% (7/7), 653 bytes | 0 bytes/s, done.
        Total 7 (delta 4), reused 0 (delta 0)
    
    $ git status ./
    On branch master-blah1
    Your branch is up-to-date with 'origin/master-blah1'.
    nothing to commit, working directory clean
    
    Git Baby is a git and github fan, let's start git clone.