NonFastForward Updates

When you push changes to the central git repository of a GNOME module, it only makes sense to accept changes if they build on top of what is already in the public branch. That is, in git speak, the current HEAD of the remote branch must be an ancestor of the stuff you are pushing onto it. In git speak, again, this is called a fast-forward merge. Details follow.

The exact error message you get if you try to push a non-fast-forward branch to GNOME repositories is:

You are trying to update the branch '$branchname' in a way that is not
a fast-forward update. Please see:

  http://live.gnome.org/Git/Help/NonFastForward

Say, you have cloned the master repository and have committed some new code. At this point your git repository may partially look like this:

    ---- time --->

          origin/master
          v
 o--o--o--o--o--o--o <-- master

where origin/master is what's in the central repository's master branch, and master is your local working branch (similarly for branches other than master or remote repositories other than origin).

Now if use some advanced git commands to modify old commits that are already in the remote repository, or delete your master branch and create it off another commit, you may end up with a repository that looks like this:

          origin/master
          v
 o--o--o--o
     \
      o--o--o <-- master

If you try to push master to origin now, it has to discard the two commits at the tip of origin/master and add your new commits. This is what the non-fast-forward push is. And this is disallowed.

In most cases, all you need to fix this is to rebase your changes on top of the origin/master branch. That is:

git rebase origin/master

This will (after resolving conflicts) take you back to the fast-forward scenario:

          origin/master
          v
 o--o--o--o--o--o--o <-- master
     \
      o..o..o <-- dead, old, master before git-rebase

For more information see git-merge manual. For much more information about branches and merging see this article.

Git/Help/NonFastForward (last edited 2009-04-24 04:10:17 by BehdadEsfahbod)