Git command aliasing

shortcuts and combinations for common Git commands

noted2023-10-02 02:20

Git command aliasing allows us to improve upon our git workflow with Git commands

Shortening Git commands

Instead of typing out a command line git status entirely, we could configure our command lines so that we can type just git s (or git st or whatever):

$ git config --global alias.s status
$ git s

The Git manual recommends other aliases:

$ git config --global alias.co checkout
$ git config --global alias.br branch
$ git config --global alias.ci commit

Combining Git commands

We could also combine git add and git commit into one command:

$ git config --global alias.add-commit '!git add -A && git commit'
$ git add-commit -m 'my commit message'

Combining the above two, we can do something like:

$ git config --global alias.ac add-commit
$ git ac -m "my commit message"

Also, we can generalize the format as:

$ git config --global alias.{alias} {command}
$ git {alias} [flags]

Other examples

Short for git push origin master (pushing to the cloud):

$ git config --global alias.pom 'push origin master'
$ git pom

Short for git checkout -b {branch-name} (checking into a new branch):

$ git config --global alias.cob 'checkout -b'
$ git cob {new-branch-name}

Enjoy!