Last active
May 3, 2019 08:47
-
-
Save jlis/1be9be73d40633593dc94394106b8ece to your computer and use it in GitHub Desktop.
Push git branches to a new remote
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
#!/usr/bin/env bash | |
if [ "$1" == "" ]; then | |
echo "Usage: ./push_to_new_remote.sh <git folder> <name of the new git remote>" | |
exit 1 | |
fi | |
if [ "$2" == "" ]; then | |
echo "Usage: ./push_to_new_remote.sh <git folder> <name of the new git remote>" | |
exit 1 | |
fi | |
cd $1 | |
remote="$2" | |
for branch in $(git for-each-ref --format='%(refname)' refs/heads/); do | |
branch="${branch//refs\/heads\//}" | |
echo "Checking branch '$branch'..." | |
if git show-branch remotes/$remote/$branch > /dev/null 2>&1; then | |
echo "Branch $branch already exists on $remote" | |
echo "Skipping..." | |
else | |
while true; do | |
read -p "Do you wish to push $branch to $remote? (y/n) " yn | |
case $yn in | |
[Yy]* ) | |
echo "Pushing branch to remote..." | |
git push $remote $branch | |
echo "Done!" | |
break;; | |
[Nn]* ) | |
echo "Skipping..." | |
break;; | |
* ) | |
echo "Please answer y for yes or n for no.";; | |
esac | |
done | |
fi | |
echo "" | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment