Skip to main content

Git Config Alias

Git config alias is a command that allows you to create a shortcut for a long command. For example, if you want to create a shortcut for the git status command, you can use the following command:

git config --global alias.s status

The --global option allows you to set the alias for all repositories on your computer. If you want to set the alias for a specific repository, you can omit the --global option.

After you have created the alias, you can use the shortcut to run the command. For example, if you want to run the git status command, you can use the following command:

git s

The following table lists some of the most commonly used git config alias commands:

CommandDescription
git config --global alias.s statusCreate a shortcut for the git status command
git config --global alias.c commitCreate a shortcut for the git commit command
git config --global alias.a addCreate a shortcut for the git add command
git config --global alias.l logCreate a shortcut for the git log command
git config --global alias.co checkoutCreate a shortcut for the git checkout command
git config --global alias.br branchCreate a shortcut for the git branch command
git config --global alias.r resetCreate a shortcut for the git reset command
git config --global alias.d diffCreate a shortcut for the git diff command
git config --global alias.st stashCreate a shortcut for the git stash command
git config --global alias.p pullCreate a shortcut for the git pull command
git config --global alias.pu pushCreate a shortcut for the git push command
git config --global alias.m mergeCreate a shortcut for the git merge command
git config --global alias.r rebaseCreate a shortcut for the git rebase command

Config alias in .gitconfig

You can also create a shortcut for a git command by adding the following line to the .gitconfig file:

~/.gitconfig
[alias]
s = status
c = commit
a = add
l = log
co = checkout
br = branch
r = reset
d = diff
st = stash
p = pull
pu = push
m = merge
r = rebase

Useful Git Config Alias tags

--pretty

The --pretty option allows you to format the output of the git log command. For example, if you want to display the commit message in a single line, you can use the following command:

git log --pretty=oneline

The following table lists some of the most commonly used --pretty options:

OptionDescription
onelineDisplay the commit message in a single line
shortDisplay the commit message in a single line with the commit hash and author
fullDisplay the commit message in a single line with the commit hash, author, and date
fullerDisplay the commit message in a single line with the commit hash, author, date, and commit message
format:%sDisplay the commit message in a single line with the commit hash and author

In format:%s, %s is a placeholder for the commit message. You can use other placeholders to display other information. For example, if you want to display the commit hash and author, you can use the following command:

git log --pretty=format:"%h - %an, %ar : %s"

My favorite --pretty option example is the following command:

lg = log --graph --pretty='format:"%C(yellow)%h %C(green)%d %C(blue)%ar %C(white)%s %C(magenta)(%cn)"'

The following image shows the output of the lg command:

Git lg command output

to sum up, it is a good practice to create a shortcut for a git command. It will save you a lot of time and effort.