Skip to content

Instantly share code, notes, and snippets.

@goneri
Created April 2, 2020 19:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save goneri/c0fab52388465f5da2b2979ee5166f08 to your computer and use it in GitHub Desktop.
Save goneri/c0fab52388465f5da2b2979ee5166f08 to your computer and use it in GitHub Desktop.
Push a given commit on Github
#!/bin/bash
set -eux
commits=$*
current_dir=$(pwd)
temp_dir=$(mktemp -du)
github_user=$(git config --get github.user)
origin_url=$(git config --get remote.origin.url)
project=$(git config --get remote.origin.url|sed 's,/$,,'|sed 's,.*/,,')
if [[ $project == "ansible" ]]; then
master_branch=devel
else
master_branch=master
fi
git clone $current_dir $temp_dir
cd $temp_dir
git remote add upstream ${origin_url}
git remote add remote_gh git@github.com:${github_user}/${project}
git fetch upstream
for commit in ${commits}; do
target_branch=$(git log -n1 --pretty=format:%f ${commit})
temp_branch=${target_branch}_${RANDOM}
git checkout -b ${temp_branch} upstream/${master_branch}
git cherry-pick ${commit}
git push remote_gh -f ${temp_branch}:${target_branch}
done
rm -rf ${temp_dir}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment