Last active
June 28, 2017 16:26
-
-
Save msawangwan/ff2ae0280c5532c6c1d75f32fa33adf2 to your computer and use it in GitHub Desktop.
[git][bash] automate 'git push' to all remote references
This file contains hidden or 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 | |
# author: misha '@mad.meesh' sawangwan | |
# i got tired of typing 'git push <remote_repo>' for | |
# each of the remotes referenced by my local repository so | |
# i wrote up a quick lil' script to automate the process. | |
# | |
# it's pretty simple and likely contains bugs but it does | |
# what i need right now and i didn't want to distract | |
# from my real project(s) by scrutinizing over all the details | |
# of a utility script. | |
# | |
# anyway, to use: | |
# | |
# - add the script to your $PATH, then you can ... | |
# - $ git-push-repos <remote_name_1> <remote_name_2> ... | |
# | |
clear | |
echo 'preparing to execute a push to selected repositories ...' | |
echo | |
echo 'working directory ...' | |
echo | |
pwd | |
echo | |
echo 'local repository status ...' | |
echo | |
git status | |
echo | |
echo 'pushing local commits ...' | |
for arg in "$@"; do | |
repo=$arg | |
# if [[ "$#" -eq 0 ]]; then | |
# repo="prod" | |
# fi | |
echo | |
echo "current remote repository to update: $repo" | |
echo | |
case "$repo" in | |
origin) | |
echo "push to: $repo" | |
git push origin master | |
;; | |
backup) | |
echo "push to: $repo" | |
git push backup master | |
;; | |
staging) | |
echo "push to: $repo" | |
git push staging master | |
;; | |
production) | |
echo "push to: $repo" | |
git push production master | |
;; | |
save) | |
echo "pushing to $repo repos" | |
echo | |
git push origin master | |
git push backup master | |
break | |
;; | |
dev) | |
echo "pushing to $repo repos" | |
echo | |
git push origin master | |
git push backup master | |
git push staging master | |
break | |
;; | |
prod) | |
echo "pushing to $repo repos" | |
echo | |
git push origin master | |
git push backup master | |
git push staging master | |
git push production master | |
break | |
;; | |
*) | |
echo "$repo is not a valid repository ..." | |
echo "... no action taken." | |
continue | |
;; | |
esac | |
done | |
echo | |
echo 'finished updating remote repositories ...' | |
echo | |
git status | |
echo | |
echo 'done.' | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment