Skip to content

Instantly share code, notes, and snippets.

@heybenchen
Last active March 10, 2016 20:11
Show Gist options
  • Select an option

  • Save heybenchen/4effc7553dad89e23b36 to your computer and use it in GitHub Desktop.

Select an option

Save heybenchen/4effc7553dad89e23b36 to your computer and use it in GitHub Desktop.
Git Checkout by Branch Index
function gc() {
git branch | sed -n $1p | xargs -n 1 git checkout
}
@heybenchen
Copy link
Author

Add to your .profile or .bash_profile

Usage:

$ git branch
master
my-other-branch
my-third-branch

$ gc 2
Switched to branch 'my-other-branch'

$ gc 3
Switched to branch 'my-third-branch'

$ gc 1
Switched to branch 'master'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment