Skip to main content

Command Palette

Search for a command to run...

Git command aliasing

substituting keywords for other words

Updated
2 min readView as Markdown
Git command aliasing

We can configure Git commands for various purposes:

Shortening Git commands

Instead of typing out a command line git status entirely, we can configure our command line so that we can just type git s (or git 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

This answer to a Stack Overflow question combines git add and git commit into one git add-commit:

$ 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'

Thus, we can generalize the format as:

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

Other examples

Configuring a "push to origin" command

Short for git push origin branchname (push to the cloud!)

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

# pushes to branch named branchname
$ git pom

Configuring a "checkout new branch" command

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

$ git config --global alias.cob 'checkout -b'

$ git cob anybranchname

Enjoy!

Git command aliasing