czbnaq
Last Updated: February 25, 2016
·
9.572K
· 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 http://stackoverflow.com/a/16074054/612530 for the info on tracking all branches locally.