Skip to content

Instantly share code, notes, and snippets.

@gildas
Created July 7, 2022 13:23
Show Gist options
  • Save gildas/dc8f4e7e40f7416c263813b35f2a8ba3 to your computer and use it in GitHub Desktop.
Save gildas/dc8f4e7e40f7416c263813b35f2a8ba3 to your computer and use it in GitHub Desktop.
git push all remotes
#
# git push all and tags to origin or other repo
#
# This assumes git config push.default matching
function gpA {
local VERBOSE=${VERBOSE:-0}
while (( $# > 0 )); do
[[ $1 == --*=* ]] && set -- "${1%%=*}" "${1#*=}" "${@:2}"
case $1 in
--quiet)
VERBOSE=0
;;
-v|--verbose)
VERBOSE=$((VERBOSE + 1))
(( VERBOSE > 2 )) && set -o xtrace # trace commands before they are executed
;;
-?*|--*=) # Invalid options
;;
--) # Force end of options
shift
break
;;
*) # Positional Argument
ARGS+=( "$1" )
;;
esac
shift
done
local remotes=( $(git remote -v | grep push | cut -f1) )
for remote in ${remotes[@]}; do
(( VERBOSE )) && echo "Pushing to $remote"
git push $remote
(( VERBOSE )) && echo "Pushing tags to $remote"
git push --tags $remote
done
}
gpA "$@"
# vim: set syntax=zsh:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment