Bill Katz

My Brain

An occasionally updated repository of thoughts, past work, and links.

Git: Commit, Push, Amend, Push Error

I'm a fan of the git version control system, but distributed revision control forces you to think a lot more.  Today, I ran into a gotcha that I'm documenting to help the next poor schlep.
I'm the only developer working on my web projects, so unless I'm merging changes across forked projects, merge conflicts don't rear their ugly head.  I like using dropbox to keep a naked clone of my repositories, just in case I have disk failures.

My normal procedure is to work on my MacBook Pro, commit to my local git repo, occasionally push to dropbox (no auto hook here yet), and maybe test the code on my Windows machine.  Today, when I tried to push my repo to dropbox, I got an error message like this:

! [rejected]    master -> master (non-fast forward)
error: failed to push some refs to /Users/me/dropbox/repos/foo.git
 
If you Google around, you'll see a way around this error is "git push --force."  It occurs when you push to a remote repo and then modify the previous commit in some way.
 
In my case, I used "git commit --amend" after I had pushed.  So if you modify commits after they are pushed, expect this kind of "non-fast forward" error.

Category: git Software

Comments are closed

1 Comments

  1. Re: Article by Roshambo (2009-02-16)

    Interesting; I just ran into the same problem, however a 'git push --force' strangely didn't work for me. Instead I had to first 'git pull' (which caused a merge to take place). After this, 'git push' worked fine. It's a bit of a chafe to have that merge in the history, though, as I intended for 'git commit --amend' to clean things up.

    In git's defense, however, I believe the manpages warn about the perils of  amending a commit after pushing.