Last Updated: February 25, 2016
· muzzlefork

How to clone all branches and tags between remote git repositories

Need to move from a local git remote (ie Atlassian Stash) to somewhere else? Like BitBucket or GitHub? Here's a way to get all those feature branches and tags, not just the ones you already have locally moved across.

# Clone a temporary copy of your repo
cd /tmp
git clone ssh://git@yourrepohost/yourrepo.git
cd yourrepo

# Start tracking all the remote branches locally
for remote in `git branch -r | grep -v '\->'`; do git branch --track $remote; done

# Remove your old origin
git remote rm origin

# Add your new remote
git remote add origin ssh://git@newrepohost/yourrepo.git

# Now push it up to the new host
git push -u --all origin

And off you go.

Hat tip to for the info on tracking all branches locally.