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

Tags:

Git