Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Alias for copying commits between forks
copycommit () {
if [ $# -lt 2 ]; then
echo -e "Usage:\n copycommit /path/to/repo commithash1 commithash2 ..."
return 1
shift 1
if [ ! -d "$repo" ]; then
echo "$repo is not a git repo"
return 1
git --git-dir="$repo" format-patch -k -1 --stdout $@ | git am -3 --ignore-whitespace
if [ $? ]; then
echo '----'
echo 'Merge failed, running "git am --abort" and creating patch: ./tmp.patch'
git am --abort
git --git-dir=$repo format-patch -k -1 --stdout $@ > ./tmp.patch
echo 'Edit patch ("vi tmp.patch") and re-apply ("git am -3 -k < tmp.patch") or give up and copy pasta the code.'
return 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.