Github Branch is ahead message not clear

git: Your branch is Ahead by X commits

Git branch is ahead of origin/master

I have read both questions above and it still does not answer my questions. Basically what I did was

  • Create a new repository in GitHub.
  • Clone and get the data in my local linux box
  • Make changes do "git add" then do a "git commit -m "message"
  • Finally do a "git push https://github.com/username/sandbox.git". This works fine and I use the https protocol that is advised instead of the SSH protocol (Please note if I do just "git push" it uses the SSH protocol which I have not configured yet and it fails)
  • Perform "git pull https://github.com/username/sandbox.git" and also "git fetch https://github.com/username/sandbox.git" all of which performed successfully saying "Already up-to date".
  • Visit the github website and I can see the changes.
  • Now run "git status" and I now see the following

    On branch master
    Your branch is ahead of 'origin/master' by 9 commits.

  • This was not what I expected. Can someone tell me why git thinks I am ahead of the origin/master by 9 commits. I have pushed and pulled the data so I would expect my local repo to be in perfect sync with the remote master/origin repo.

    The command "git branch -av" shows the following

     * master                a99daf0 [ahead 9] submit
      remotes/origin/HEAD   -> origin/master
      remotes/origin/master 81c7ec1 remove out files
    

    You are ahead of origin/master because you have committed your own patches to the current branch.

    This can be shown with:

    $ git branch -av
    master         0123abcd [ahead 9] Current commit comment
    

    This reason for this is that your local branch is your own private copy and not actually the same as origin/master. Although your local branch master is setup to track the origin/master . So git is informing you of the difference between the two branches.

    The command above will show the point where master is and you will see another entry for origin/master .

    Now if you did your push and then a fetch and then a pull the current commit-id (shown in git branch -av ) should be the same. If not you need to work out why not. Maybe:

    $ git log origin/master..master   # this can help explain ?  OR...
    $ git diff origin/master..master  # this can help explain
    

    Check the commit-id you see via HTTP/browser at github is the same commit-id's reported in which branch from git branch -av .

    If it turns out that there is no difference you can always checkout a new branch, switch to it and then try to delete the old master branch git branch -d master by default it won't let you if there are patches that would be lost (because they have not been merged and pushed into the upstream master).

    If it won't let you delete the branch. You can ask git to tell you at which commit-id do two branches share the same heritage ("they both started life as the same version, when was that?").

    $ git merge-base origin/master master
    

    This will show you the last commit the two branchs share. From that point each branch diverged in their own way. You can take that commit-id and then compare the log output:

    $ git log <commit-id>..<branch_name> --oneline
    $ git log <commit-id>..<other_branch_name> --oneline
    

    You can now see how they become different.


    As a newbie what I actually needed was the answer described by "Mims H Wright" at How can I find the location of origin/master in git, and how do I change it? which eventually points to the link http://fvue.nl/wiki/Git%3a_Your_branch_is_ahead_of_the_tracked_remote_branch.

    Basically I had to do

    git push origin master:master
    
    链接地址: http://www.djcxy.com/p/23154.html

    上一篇: 执行git状态时遇到问题

    下一篇: Github分支领先消息不明确