git aliases are useful command-line shortcuts to save a minute or two here and there while working with your version-controlled source code (or other data).
To use it, just add the following line to your `~/.gitconfig`
[alias] default = "!git remote show origin | grep 'HEAD branch:' | cut -d ' ' -f 5" fb = "!git fetch origin && git checkout -t origin/$(git default) -b"
To use this, you can run these aliased commands in a repository directory:
git defaultto get the default remote branch.
git fb try/some-new-featureto create a new feature branch based on the remote default branch. (
fbis short for “feature branch,” of course).
- 2022-12-30 to add the separate
defaultalias I’ve been using as well.
- 2020-07-21 to continue to work with repositories that have moved away from calling the default branch
master(Github is changing the default).