Home
Alt + H
Logo Logo

Tips & Tricks

Git Aliases: Typing less, doing more — My favorite shortcuts

Tags 5 min read Comments
Post - Git Aliases: Typing less, doing more — My favorite shortcuts

Summary

Show content

Introduction

In a developer/I.T. roadmap, Git is one of the first (and most essential) tools to learn. It helps developers track file changes and maintain a history of every modification. But when you find yourself typing the same commands multiple times a day or struggling to remember a long one, it quickly becomes boring.

So, in this short post, I’ll share some of my favorite Git Aliases Git Aliases that I use daily. With aliases, you can create shortcuts that save your keyboard time.

Why use Git aliases?

  1. Save time by reducing repetitive typing.
  2. Simplify complex commands into shortcuts.
  3. Customize Git to fit your needs.

But, wait. We need to talk about something important: Why don't use Git aliases?

Why don’t use Git aliases?

Well, using this aliases can produce some unwanted behaviors:

  1. Can make it harder to work on systems where those aliases aren’t used.
  2. Can make Git commands feel like magic, which isn’t always a good thing.
  3. Using aliases adds a small initial learning curve.

Sure, we can always verify the command behind the shortcut, but it can be annoying sometimes.

Setting up aliases

First of all, let’s see how we can set up aliases using Git:

You can define using the following command:

Terminal window
1
git config --global alias.co checkout

Or edit your ~/.gitconfig file manually:

1
[alias]
2
co = checkout
3
ss = status
4
cmm = commit -m

On Linux, you can find your .gitconfig file in ~/, while on Windows, Git looks for it in the $HOME directory (typically C:\Users\$USER).

My favorite ones

Over the years of using Git aliases, I’ve created my own shortcuts, short and simple (well, most of the time) to remember:

AliasCommandDescription
ccloneClone a repository
cnfconfig —listShow current Git configuration
dddiffShow changes between commits or working state
dldiff HEAD~Show changes from the last commit
lllogView commit history
ltlog -1 HEADShow the latest commit
llglog —graphDisplay commit history as a graph
ssstatusShow the working tree status
aaadd .Stage all changes
aAadd -AStage all changes, including deletions
plpullFetch and merge changes from a remote repo
plssubmodule update —recursive —remoteUpdate all submodules recursively
phpushPush changes to the remote repository
pho”!f(){ git push -u origin ${1}; };f”Push to a new remote branch
cmcommitSave changes to the repository
cmmcommit -mCommit with a message
cmecommit —allow-empty -mCommit an empty change with a message
cmacommit —amend -mModify the last commit message
brbranchList, create, or delete branches
brdbranch -dDelete a local branch
brrbranch -mRename a branch
cocheckoutSwitch branches or restore files
cobcheckout -bCreate and switch to a new branch
ftfetchDownload changes from a remote repository
ftpfetch —pruneFetch and remove deleted remote branches
resrestoreDiscard changes in the working directory
ressrestore —stagedUnstage changes without discarding them
rtHreset HEAD~Undo the last commit
shstashSave uncommitted changes for later
shastash applyApply the latest stashed changes
swswitchSwitch between branches
mmmergeMerge branches

That’s a really looong list, and can contains more shortcuts over time. But with time and practice you can combine commands and reduce the typing.

Use case

Imagine this:

I forgot to commit my changes and ended up starting a new feature. Now, I need to move all the changes to a new branch and commit/push them to the remote repository.

In this case, we can use this “command combo”:

  1. git sh: Stash all uncommitted changes
  2. git cob feat/x: Create and switch to a new branch
  3. git sha: Apply the stashed changes to the new branch
  4. git aa: Stage all changes
  5. git cmm “wip: start feature X”: Commit with a message
  6. git pho feat/x: Push new branch to remote

Shortening even more

For even faster typing (or laziness), you can alias git itself to g. In your ~/.bash_profile, add the following alias:

Terminal window
1
alias g='git'

Usage example:

Terminal window
1
g cmm "feat: my new feature"

Conclusion

Now that you know how to create aliases, start experimenting with your own shortcuts to fit your needs.

Got any good Git command shortcuts to share? Leave it in the #comments section :)

Resources and References

Enjoy this post? Feel free to share!

Git Aliases: Typing less, doing more — My favorite shortcuts



Share to LinkedIn
Share to Twitter
Share to Reddit
Copy link
QR Code

Comments

RSS
Tags
Source Code
Logo Logo
Lucas Josino
© 2025 • Built with Astro