Skip to content

Instantly share code, notes, and snippets.

@drbrain
Last active August 18, 2023 18:45
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 drbrain/1e998cbcc328e8d6193a3bf9382dffb5 to your computer and use it in GitHub Desktop.
Save drbrain/1e998cbcc328e8d6193a3bf9382dffb5 to your computer and use it in GitHub Desktop.
Switch to the default branch of this git repository
#!/bin/sh
# git-default
#
# Switch to the repository's default branch
default=`git symbolic-ref refs/remotes/origin/HEAD | cut -d '/' -f 4`
current=`git branch --show-current`
if [ "x${default}" = "x${current}" ]; then
exit 0
fi
git switch ${default}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment