Last active
February 3, 2016 20:43
-
-
Save mfessenden/184c70f398c4cd842522 to your computer and use it in GitHub Desktop.
Clone a git repository and track all remote branches
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
#!/bin/bash | |
if [[ $1 =~ ([a-zA-Z\-]+)(\.git)$ ]] | |
then | |
# clone the repo | |
echo "-> cloning $1" | |
git clone $1 | |
# regex the directory name | |
REPO_DIRNAME=${BASH_REMATCH[1]} | |
# drop into the new repo directory | |
cd $REPO_DIRNAME | |
# clone all of the remote branches to track | |
for i in $(git branch -r | grep -vE "HEAD|master"); do git branch --track ${i#*/} $i; done | |
else | |
echo "cannot" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment