Clone all branches and tags at once
Following script clone all #git branches and tags at once:
#!/bin/bash
git fetch --all --tags
for branch in `git branch -r --format="%(refname:short)" | sed 's/origin\///'`
do git branch -f --track "$branch" "origin/$branch"
done
Single line version:
git fetch --all --tags; for branch in `git branch -r --format="%(refname:short)" | sed 's/origin\///'`; do git branch -f --track "$branch" "origin/$branch" ; done ;
Motivation?
This command is super usefull when you need copy repo between remotes:
git remote add alternative git@github.com:....git
Check if is there another remote:
git remote -v
> origin git@github.com:.../....git (fetch)
> origin git@github.com:.../....git (push)
> alternative git@github.com:.../....git (fetch)
> alternative git@github.com:.../....git (push)
Push all changes to alternative remote
git push alternative --all # push all braneches
git push alternative --tags # push all tags