How to Create Short Git Aliases for Frequently Used Commands
Running a command like git config --global alias.st status lets you type git st to run git status. This setting is useful when you are tired of typing long commands such as git log --oneline --graph --all every time, or when you want to make your Git operations in the terminal a bit shorter. I ran git in a test environment and included the output from before and after creating the alias exactly as it appeared.
The test environment is Ubuntu 24.04 with Git 2.43.0. I set the author name and email to example values (Neko <neko@example.com>), and I fixed the commit dates with environment variables. I ran with the system-wide config file not read (GIT_CONFIG_NOSYSTEM=1) and with the pager turned off. I did not test Windows or macOS, or how to write these in shells other than bash.
- 1. Running git st before creating an alias
- 2. Setting alias.name with git config
- 3. Checking the aliases you created
- 4. You cannot use the same name as an existing command
- 5. When the contents contain a typo
- 6. Starting the value with ! runs a shell command
- 7. Aliases used only in this repository
- 8. Removing aliases you no longer need
Running git st before creating an alias
When no alias exists and you type git st, Git says there is no such command. It suggests similar command names, but it does not run any of them.
$ git st
git: 'st' is not a git command. See 'git --help'.
The most similar commands are
status
reset
stage
stash
The Git Aliases section of Pro Git also notes that Git does not guess a command from a partial name. If you want to run a command under a short name, you need to create an alias yourself.
Setting alias.name with git config
You create an alias with git config as a setting named alias.<short name>. Adding --global makes it available in every repository for that user.
$ git config --global alias.st status
$ git st
On branch main
nothing to commit, working tree clean
The output of git st matched git status. Any arguments you add after the alias are passed through to the original command. For example, git st -s is the same as git status -s and shows the short format (used in the unstage example below).
Naming a command with options
If you want the options included in a single name, wrap the whole value in quotes. Here I make lg a command that shows the history one line per commit as a graph.
$ git config --global alias.lg "log --oneline --graph --all"
$ git lg
* 7e6795a トップ画面を追加
* b6eccb8 ログイン画面を追加
* 6b9961f 最初のコミット
$ git lg -2
* 7e6795a トップ画面を追加
* b6eccb8 ログイン画面を追加
When you add an argument such as git lg -2, it is appended after the contents of the alias. Here it ran as git log --oneline --graph --all -2, and only two entries were shown.
I also made last (to show the last commit), which is an example given in Pro Git.
$ git config --global alias.last "log -1 HEAD"
$ git last
commit 7e6795a402aa1c1620a9aac9f3e3b149c1020f39
Author: Neko <neko@example.com>
Date: Thu Nov 12 10:20:00 2026 +0900
トップ画面を追加
Creating a command with an easy-to-remember name
Aliases are also useful for giving a memorable name to an operation that is hard to remember. I gave the name unstage to git restore --staged --, which removes files from the staging area.
$ git config --global alias.unstage "restore --staged --"
$ printf "猫の写真を集めるアプリです。\n" >> README.md
$ git add README.md
$ git st -s
M README.md
$ git unstage README.md
$ git st -s
M README.md
As described in the git status reference, the left column of the short format shows the index (staging area) and the right column shows the working tree. Before git unstage README.md, the M was in the left column; after it, the M moved to the right column. The contents of the file were unchanged, and only the staging was undone.
Checking the aliases you created
To see what an alias expands to, use git help <alias name>.
$ git help st
'st' is aliased to 'status'
$ git help lg
'lg' is aliased to 'log --oneline --graph --all'
To list all the aliases you have created, search for settings starting with alias. using git config --get-regexp. Adding --show-scope also shows which configuration file each one comes from, either global or the repository's local.
$ git config --global --get-regexp "^alias\."
alias.st status
alias.lg log --oneline --graph --all
alias.last log -1 HEAD
alias.unstage restore --staged --
$ git config --show-scope --get-regexp "^alias\."
global alias.st status
global alias.lg log --oneline --graph --all
global alias.last log -1 HEAD
global alias.unstage restore --staged --
When I ran the same git config --global --get-regexp "^alias\." before creating any aliases, nothing was displayed.
As described in the git config reference, aliases created with --global are written to ~/.gitconfig in your home folder. When you open the file, they are listed under [alias].
$ cat ~/.gitconfig
[init]
defaultBranch = main
[user]
name = Neko
email = neko@example.com
[alias]
st = status
lg = log --oneline --graph --all
last = log -1 HEAD
unstage = restore --staged --
You cannot use the same name as an existing command
Even if you want git status to always show the short format and create an alias named status, it has no effect.
$ git config --global alias.status "status -s"
$ git config --global --get alias.status
status -s
$ git status
On branch main
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: README.md
no changes added to commit (use "git add" and/or "git commit -a")
The setting is saved, but git status still displays the original long format. The description of alias.* in the git config reference says that, to avoid confusion and problems in scripts, aliases that hide existing Git commands are ignored. I removed this alias with git config --global --unset alias.status.
When the contents contain a typo
If you misspell a command name inside an alias, the error only appears when you use the alias. Here switch was mistyped as swich.
$ git config --global alias.sw swich
$ git sw main
expansion of alias 'sw' failed; 'swich' is not a git command
$ git config --global alias.sw switch
$ git sw main
Already on 'main'
M README.md
The message expansion of alias 'sw' failed shows which alias has broken contents. Running git config again with the same name overwrites the value and fixes it.
Starting the value with ! runs a shell command
If the value starts with !, it is run as a shell command instead of a Git subcommand. Since such values often contain " or $, wrapping the whole value in single quotes makes it easier to write.
Note that an alias starting with ! runs in the top-level folder of the repository. I tried an alias that lists files from inside the subfolder src. Each line that begins with cd src && 〜 moved from the top of the repository into src and ran from there (I returned to the top before typing each line).
$ git config --global alias.files '!ls'
$ cd src && ls
login.txt
top.txt
$ cd src && git files
README.md
src
Typing ls inside src shows the contents of src, but git files showed the contents of the top of the repository. The git config reference also says that shell commands run in the top-level folder of the repository, not necessarily in the folder you are in.
The original folder is stored as a path relative to the top, in the environment variable GIT_PREFIX. When I rewrote the alias to move there before running, it showed the contents of src. Running git files from the top-level folder still showed the top-level contents as before. ${GIT_PREFIX:-.} is shell syntax for using . (the current folder) when GIT_PREFIX is empty.
$ git config --global alias.files '!cd -- "${GIT_PREFIX:-.}" && ls'
$ git config --global --get alias.files
!cd -- "${GIT_PREFIX:-.}" && ls
$ cd src && git files
login.txt
top.txt
$ git files
README.md
src
Inserting arguments in the middle
Arguments you add to a ! alias are also appended at the end of the command. Using echo to check, login appeared after 引数:.
$ git config --global alias.say '!echo 引数:'
$ git say login
引数: login
If you want to place an argument in the middle of the command, define a shell function, call it immediately, and receive the argument inside the function as $1. The latest git config reference also recommends this form. The following alias creates a branch named feature/login with git feat login.
$ git config --global alias.feat '!f() { git switch -c "feature/$1"; }; f'
$ git config --global --get alias.feat
!f() { git switch -c "feature/$1"; }; f
$ git feat login
Switched to a new branch 'feature/login'
$ git branch
* feature/login
main
Aliases used only in this repository
If you run git config inside a repository without --global, the alias is stored in that repository's .git/config and is only available there.
$ git config alias.s "status -s"
$ git s
M README.md
$ git config --show-scope --get-regexp "^alias\."
global alias.st status
global alias.lg log --oneline --graph --all
global alias.last log -1 HEAD
global alias.unstage restore --staged --
global alias.sw switch
global alias.files !cd -- "${GIT_PREFIX:-.}" && ls
global alias.say !echo 引数:
global alias.feat !f() { git switch -c "feature/$1"; }; f
local alias.s status -s
$ cat .git/config
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[alias]
s = status -s
In the list, only s is shown as local.
Removing aliases you no longer need
To remove an alias, use --unset and specify the same scope you used when creating it (with or without --global).
$ git config --global --unset alias.lg
$ git lg
git: 'lg' is not a git command. See 'git --help'.
The most similar command is
log
$ git config --show-scope --get-regexp "^alias\."
global alias.st status
global alias.last log -1 HEAD
global alias.unstage restore --staged --
global alias.sw switch
global alias.files !cd -- "${GIT_PREFIX:-.}" && ls
global alias.say !echo 引数:
global alias.feat !f() { git switch -c "feature/$1"; }; f
local alias.s status -s
git lg returned to the same error as git st before the alias was created, and lg disappeared from the list.




