How do I resolve a GitHub message that says the tip of my current branch is behind its remote counterpart?

28,439

Someone (or you) have updated the remote branch. That causes your remote branch become ahead of your current branch. (that is your local branch)

I suggest you to git pull --rebase origin master and push after that.

Share:
28,439
incandescentman
Author by

incandescentman

Updated on July 02, 2020

Comments

  • incandescentman
    incandescentman almost 4 years

    I am trying to learn how to use GitHub to version-control my work as I go. (I work alone, no collaborators, no different branches, just me backing up my work as I go.) I have set up private Git repositories at BitBucket.org. I am using GitHub for OSX as my Git GUI.

    But when I make edits to the files in my local Git repository on my hard drive, then use GitHub for OSX to try to "Commit & Sync," I get this error:

    git: 'credential-osxkeychain' is not a git command. See 'git --help'.
    git: 'credential-osxkeychain' is not a git command. See 'git --help'.
    2013-02-12 02:49:07.409 GitHub for Mac Login[44516:707] AskPass with arguments: (
        "/Applications/GitHub.app/Contents/MacOS/GitHub for Mac Login",
        "Password for 'https://[email protected]': "
    )
    git: 'credential-osxkeychain' is not a git command. See 'git --help'.
    git: 'credential-osxkeychain' is not a git command. See 'git --help'.
    To https://[email protected]/username/data.git
     ! [rejected]        master -> master (non-fast-forward)
    error: failed to push some refs to 'https://[email protected]/username/data.git'
    hint: Updates were rejected because the tip of your current branch is behind its remote counterpart. Merge the remote changes (e.g. 'git pull') before pushing again. See the 'Note about fast-forwards' in 'git push --help' for details.
     (256)
    

    (I edited the above to conceal my actual username.)

    What does this mean, how do I resolve it, and how do I avoid getting it in the future?

  • incandescentman
    incandescentman about 11 years
    I definitely did not edit the code at bitbucket.org. The only thing I've been doing is syncing using GitHub for OSX, and doing "git add -A" or "git add -u" and "git commit" from the CLI. I did do a rollback to a previous commit, maybe that's the problem? In any case my local files are the canonical version so I don't want to do a pull. How do I resolve the error and push my local files?
  • ogzd
    ogzd about 11 years
    yes, that is the problem. When you do the rollback, you don't remove the commits in the remote, they just stay where they are. Try git push -f, but beware that you will lose those commits in remote.
  • incandescentman
    incandescentman about 11 years
    So does that mean I made a mistake in the way I rolled back to a previous commit? Is there a better way to do it than what I did? And does git push -f destroy the more recent version? If so, what's a correct workflow that doesn't destroy the more recent version, just in case the old version I thought was canonical really wasn't?
  • ogzd
    ogzd about 11 years
    You can create a branch and push your changes to there. In that way, the head of remote master will not changed and you can always switch to it if you want. And I think it is better than push -f because you will lose those commits when you do.
  • Victor Engel
    Victor Engel about 11 years
    I see messages about fast-forward. Is that what the -f does? It appears this may be what I've been needing to do. I think I'm in the same position as the OP. I have a local version that I want to push out, and if a remote version is farther ahead, it is wrong and needs to be abandoned. Is that what -f does? Hmmm - seems like it means force.
  • serv-inc
    serv-inc about 8 years
    @VictorEngel: yes, indeed, -f is for force: "Usually, the command refuses to update a remote ref that is not an ancestor of the local ref used to overwrite it. Also, when --force-with-lease option is used, the command refuses to update a remote ref whose current value does not match what is expected. This flag disables these checks, and can cause the remote repository to lose commits; use it with care." manual page