Patching with Git

Great article on how to create and apply a patch with Git

In my setup I used the following:

  • cd /var/tmp
  • mkdir clone_tmp
  • git clone git@github.com:details_here_removed
  • git checkout -b hotfix_branch_name  (create local branch and checkout to it)
  • now I make my changes to files (and test)
  • update my version file: git describe –tags –long > version.txt
  • git commit -a
  • git format-patch master –stdout > /tmp/hotfix_1

From here I can merge into my master branch:

  • git checkout master
  • git merge hotfix_branch_name master
  • git push origin master
  • (don’t forge to update your dev branches too!)

Now let’s apply the patch:

  • cd /my/local/src/files
  • First let’s check if things will work
    • git apply –stat /tmp/hotfix_1
    • git apply –check /tmp/hotfix_1
  • Now let’s really apply the patch
  • git apply /tmp/hotfix_1