Skip to content

Instantly share code, notes, and snippets.

@daniel-vera-g
Last active April 7, 2021 13:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daniel-vera-g/dc4df64ed1064406c8956f588c538d41 to your computer and use it in GitHub Desktop.
Save daniel-vera-g/dc4df64ed1064406c8956f588c538d41 to your computer and use it in GitHub Desktop.
Sync all branches and tags with new remote
#!/bin/bash
# To be used with: https://gist.github.com/daniel-vera-g/fcecac7103cae23ddfc80306d22fa7f0
# Sync all branches and tags with new remote
# Credits: https://gist.github.com/tamtamchik/2869690/
# Fetch all branches and tags
fetchAll() {
for branch in `git branch -r | grep -v HEAD | grep -v master`; do
echo ${branch##*/} $branch
done
echo "Fetching..."
git fetch --all
echo "Pulling..."
git pull -v
echo "Results: Branches"
git branch -a
echo "Results: Tags"
git tag
}
# Track all branches
trackAll() {
for branch in `git branch -a | grep remotes | grep -v HEAD | grep -v master `; do
git branch --track ${branch#remotes/origin/} $branch
done
}
# For all repositories in the current path:
# 1. Fetch all branches and tags
# 2. Track all branches
# 3. Push to new remote. In this case github
ls -d */ | while read repo; do
cd $repo
fetchAll
trackAll
git push github '*:*'
cd ..
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment