Skip to content

Instantly share code, notes, and snippets.

@mburgs
Forked from odrotbohm/gist:3215345
Last active August 29, 2015 13:56
Show Gist options
  • Select an option

  • Save mburgs/8850656 to your computer and use it in GitHub Desktop.

Select an option

Save mburgs/8850656 to your computer and use it in GitHub Desktop.

Base off this gist: https://gist.github.com/olivergierke/3215345 a small extension to avoid writing the checkout command, we store the hash in a variable then checkout the other branch and proceed with the cherry-picking:

[alias]
  last = !git log -n 1 --pretty=format:%H $1
  cp-last-to = "!sh -c 'HASH=`git last` && git checkout \"$0\" && git cherry-pick $HASH'"

So you can just do:

master $ git commit -m "$commitmessage"
master $ git cp-last-to dev

One thing to note is that after this command you will be in the other branch (dev in this case), ready to pull, push, or sort out conficts as necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment