Back

How to create and use git aliases for faster workflow

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:

AliasFull CommandPurpose
gsgit status -sCheck repo status in short format
gdgit diffView unstaged changes
gdsgit diff —stagedView staged changes
gagit addStage changes
gcmgit commit -mCommit with a message
gcagit commit —amendAmend last commit
gpgit pushPush to remote
gplgit pull —rebasePull and rebase local changes
glgit log —oneline —graph —decorateView commit history compactly
gcogit checkoutSwitch branches
gclgit cloneClone 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.

Listen to your bugs 🧘, with OpenReplay

See how users use your app and resolve issues fast.
Loved by thousands of developers