11

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://username@bitbucket.org': "
)
git: 'credential-osxkeychain' is not a git command. See 'git --help'.
git: 'credential-osxkeychain' is not a git command. See 'git --help'.
To https://username@bitbucket.org/username/data.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'https://username@bitbucket.org/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
  • 6,168
  • 3
  • 46
  • 86

1 Answers1

25

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.

ogzd
  • 5,532
  • 2
  • 26
  • 27
  • 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? – incandescentman Feb 12 '13 at 08:14
  • 9
    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. – ogzd Feb 12 '13 at 08:18
  • 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? – incandescentman Feb 13 '13 at 05:06
  • 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. – ogzd Feb 13 '13 at 06:54
  • 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. – Victor Engel Mar 16 '13 at 08:42
  • @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](https://git-scm.com/docs/git-push) – serv-inc Apr 28 '16 at 13:47