Skip to content

Instantly share code, notes, and snippets.

@GabriOliv
Last active December 22, 2024 10:15
Show Gist options
  • Save GabriOliv/22b9d76b5633ce726d13a364e31a8958 to your computer and use it in GitHub Desktop.
Save GabriOliv/22b9d76b5633ce726d13a364e31a8958 to your computer and use it in GitHub Desktop.
Pre-Push Git Hook for Pushing Commits to Multiple Remotes
#!/bin/sh
# Git hook script to force GIT PUSH for
# all remotes configured in the local repository.
# Name as "pre-push" and place in the ".git/hooks" folder of the repository.
# Need to give execute permission to the file: chmod +x .git/hooks/pre-push
for remote in `git remote`; do
if [ $remote != "origin" ]; then
echo "GitHook pre-push triggered: Pushing commits to all remotes";
echo "Remote: ${remote}";
git push --force $remote --no-verify;
fi
done;
# =================================================================
# To add multiple remotes to the local repository:
# String used to add multiple remotes to .git/config:
# [remote "NAME_OF_THE_REMOTE"]
# pushurl = git@URL:VAULT/REPO.git
# =================================================================
# If you want to push to all remotes without using the hook,
# You can use the following command as an alias:
# alias gitpushallremotes='for remote in `git remote`; do git push --force $remote -v; done'
# =================================================================
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment