Your branch is ahead of 'origin/master' by 3 commits

I am getting the following when running git status

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

I have read on some other post the way to fix this is run git pull --rebase but what exactly is rebase, will I lose data or is this simple way to sync with master?


You get that message because you made changes in your local master and you didn't push them to remote. You have several ways to "solve" it and it normally depends on how your workflow looks like:

  • In a good workflow your remote copy of master should be the good one while your local copy of master is just a copy of the one in remote. Using this workflow you'll never get this message again.
  • If you work in another way and your local changes should be pushed then just git push origin assuming origin is your remote
  • If your local changes are bad then just remove them or reset your local master to the state on remote git reset --hard origin/master

  • There is nothing to fix. You simply have made 3 commits and haven't moved them to the remote branch yet. There are several options, depending on what you want to do:

  • git push : move your changes to the remote (this might get rejected if there are already other changes on the remote)
  • do nothing and keep coding, sync another day
  • git pull : get the changes (if any) from the remote and merge them into your changes
  • git pull --rebase : as above, but try to redo your commits on top of the remote changes
  • You are in a classical situation (although usually you wouldn't commit a lot on master in most workflows). Here is what I would normally do: Review my changes. Maybe do a git rebase --interactive to do some cosmetics on them, drop the ones that suck, reorder them to make them more logical. Now move them to the remote with git push . If this gets rejected because my local branch is not up to date: git pull --rebase to redo my work on top of the most recent changes and git push again.


    Use these 4 simple commands

    Step 1 : git checkout <branch_name>

    This is obvious to go into that branch.

    Step 2 : git pull -s recursive -X theirs

    Take remote branch changes and replace with their changes if conflict arise. Here if you do git status you will get something like this your branch is ahead of 'origin/master' by 3 commits.

    Step 3 : git reset --hard origin/<branch_name>

    Step 4 : git fetch

    Hard reset your branch.

    Enjoy.

    链接地址: http://www.djcxy.com/p/23150.html

    上一篇: 无法同步此分支

    下一篇: 你的分支在3次提交之前超过'origin / master'