Skip to content

Instantly share code, notes, and snippets.

@mfessenden
Last active February 3, 2016 20:43
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 mfessenden/184c70f398c4cd842522 to your computer and use it in GitHub Desktop.
Save mfessenden/184c70f398c4cd842522 to your computer and use it in GitHub Desktop.
Clone a git repository and track all remote branches
#!/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