genderphasing

git aliases

because git's enough of a git as git is

mood: conveniencedtipsoftware

one useful feature of git's you may not have known about is aliases: git configuration options which let you write shorter git commands.

here are the two i use the most:

[alias]
  tree = log --oneline --all --graph
  amend = commit --amend --no-edit

the syntax here should be fairly familiar to anyone who knows ini files. you have an [alias] section, and inside that, you have your aliases, = whatever they should expand to.

more specifically, what these commands do is:

you can add them by manually editing your .gitconfig, including adding them per-repository, though i've never found a usecase for that. i prefer setting them with the command:

git config set --global alias.name 'replacement command here'

take note: don't alias it to git something! if you want git foo to run git status, you alias it to just 'status'.

if you want to alias it to a full shell command, put a ! in front, e.g.:

git config set --global alias.shell '!echo hello there'

but keep in mind:

Care should be taken if your shell alias is a "one-liner" script with multiple commands (e.g. in a pipeline), references multiple arguments, or is otherwise not able to handle positional arguments added at the end. For example: alias.cmd = "!echo $1 | grep $2" called as git cmd 1 2 will be executed as echo $1 | grep $2 1 2, which is not what you want.

A convenient way to deal with this is to write your script operations in an inline function that is then called with any arguments from the command-line. For example alias.cmd = "!c() { echo $1 | grep $2 ; }; c" will correctly execute the prior example.

git-config(1)

i would strongly recommend setting some aliases up to make your typical workflows a little easier. if you're running git at the cli, it can be one hell of a process, so optimize it!