Skip to content

Instantly share code, notes, and snippets.

@samuelcolvin
Last active March 12, 2021 18:25
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 samuelcolvin/b39536da4eb581da2ad134bea7cd47d3 to your computer and use it in GitHub Desktop.
Save samuelcolvin/b39536da4eb581da2ad134bea7cd47d3 to your computer and use it in GitHub Desktop.
switch to with master or main
gm() {
if git branch | grep -q '^[* ]*master$'; then
git checkout master
else
git checkout main
fi
}
@samuelcolvin
Copy link
Author

samuelcolvin commented Mar 11, 2021

I've always used the alias gm="git checkout master" to switch to my master branch.

I'm now moving to using main instead of master, but want gm to work on old and new projects as it used to. This tiny bash function does what I need.

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