Created
November 18, 2016 22:05
-
-
Save devdrops/ca068dd3e3623e7318607b8178a0d1cf to your computer and use it in GitHub Desktop.
Git: checkout all remote branches locally
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 | |
| # First things first | |
| current=`git branch | grep \* | cut -d ' ' -f2` | |
| git fetch --all | |
| # Once we know all the remote branches | |
| remoteprefix='remotes/' | |
| branchprefix='remotes/origin/' | |
| for branch in `git branch -a | grep remotes | grep -v HEAD | grep -v master`; do | |
| # Removing 'remotes/' | |
| remoteandbranch=${branch#$remoteprefix} | |
| # Removing 'remotes/origin/' | |
| localbranch=${branch#$branchprefix} | |
| # Remote name | |
| remote=${remoteandbranch%\/$localbranch} | |
| # Removing 'remotes/origin/' | |
| localbranch=${branch#$branchprefix} | |
| # Remote only | |
| remote=${remoteandbranch%\/$localbranch} | |
| git checkout -b $localbranch $remote/$localbranch | |
| done | |
| # Back to the current branch | |
| git checkout $current |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment