How to create and use git aliases for faster workflow

Typing full Git commands repeatedly can slow you down, especially during frequent operations like checking status, committing changes, or switching branches. What if you could perform these common tasks with just two or three keystrokes? This is where Git aliases come in.
In this article, we’ll show you how to create Git aliases to make your development workflow faster, based on proven techniques used by experienced developers.
Key Takeaways
- Git aliases shorten common commands for faster workflows
- Setting up aliases saves time and reduces repetitive typing
- You can customize aliases to fit your workflow with simple configuration edits
What are Git aliases?
Git aliases are custom shortcuts for longer Git commands. Instead of typing git status
every time you want to check your working directory, you can create a shortcut like gs
. This small change saves time and reduces friction, especially when managing many repositories daily.
Git aliases are configured either by editing your .gitconfig
file directly or by using the git config
command.
How to create Git aliases
You can create aliases manually by editing the Git configuration file located at ~/.gitconfig
under the [alias]
section.
Example:
[alias]
st = status
co = checkout
br = branch
cm = commit
pl = pull
ps = push
Alternatively, you can add them via terminal commands:
git config --global alias.st status
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.cm commit
git config --global alias.pl pull
git config --global alias.ps push
The --global
flag applies these aliases for your user across all repositories. If you omit --global
, the alias will be set for the current project only.
Most useful Git aliases to speed up your workflow
Here’s a practical set of Git aliases inspired by real-world usage from the transcript you shared:
Alias | Full Command | Purpose |
---|---|---|
gs | git status -s | Check repo status in short format |
gd | git diff | View unstaged changes |
gds | git diff —staged | View staged changes |
ga | git add | Stage changes |
gcm | git commit -m | Commit with a message |
gca | git commit —amend | Amend last commit |
gp | git push | Push to remote |
gpl | git pull —rebase | Pull and rebase local changes |
gl | git log —oneline —graph —decorate | View commit history compactly |
gco | git checkout | Switch branches |
gcl | git clone | Clone a repository |
You can adapt this list depending on the commands you use most often.
Advanced tip: improving your Git aliases
You can combine Git aliases with URL shortcuts and external tools to work even faster:
- URL Shortcuts: Set common Git hostnames (e.g., GitHub) as shortcuts so you clone repos with
git clone gh:user/repo
instead of typing full URLs. You can find more on this in the Git documentation. - Readable Diff Output: Install diff-so-fancy to make Git diffs easier to review.
Example using diff-so-fancy
:
git config --global alias.dsf "!git diff --color | diff-so-fancy"
Where Git aliases are stored
Aliases are stored in your global Git configuration file located at ~/.gitconfig
. You can open this file manually with a text editor to view or adjust them anytime.
Example excerpt from .gitconfig
:
[alias]
st = status -s
co = checkout
br = branch
cm = commit
Conclusion
Setting up Git aliases takes just a few minutes but can save hours over the long run. With short, memorable shortcuts for common Git commands, you can navigate, stage, commit, and push changes with less effort. Customize your aliases to match your workflow, and you’ll notice the speed improvement quickly.
FAQs
Yes. Aliases can accept parameters, but you need to use a shell alias with `!` to handle more complex parameter passing.
Only if you configure them on each machine. Otherwise, you can export and reuse your `.gitconfig` file.
Git aliases work in any terminal environment where Git is installed. Some GUI tools may not recognize aliases directly.