Tech note: Git patches and rebasing

So, last Friday while working on Freesound 2, I stumbled upon an interesting problem I need to solve using git. The problem is as follows: say you have a clone of a public git url (for example Now, you're making changes in this repository and at some point you want these changes back into the origin repository.

There is no way to push from a clone of a public url (you don't have rights to push), so the only way is making a patch and send that patch to someone who does have those rights. Searching about on the web taught me about some commands like "format-patch", but all was a bit unclear. format-patch creates mail-box formatted mail which contain a complete set of patches with comments and everything which you can easily send by email. A quick visit to the #git channel on Freenode IRC cleared up the sometimes dense explanation in the man pages:

  1. on clone without push rights:
           # make changes/commits all you want
           # this creates a mailable patch:
           git format-patch origin --stdout > filename.patch
           # now send this patch to whoever should do the patching
  2. on clone with push rights:
           # this "applies" the "mailbox file"
           git am 
  3. on clone without push rights:
           # pull and throw away the current changes in master
           git pull --rebase .