Skip to content

Instantly share code, notes, and snippets.

@goneri
Created Apr 2, 2020
Embed
What would you like to do?
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