Created
April 2, 2020 19:04
-
-
Save goneri/c0fab52388465f5da2b2979ee5166f08 to your computer and use it in GitHub Desktop.
Push a given commit on Github
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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