Git aliases that might come in handy

Git is a powerful tool, but it can be a bit verbose at times. So let me share some handy aliases that I use to speed up my workflow.

TLDR: Check the aliases list in my public gist

How to set em up

An alias can be setup either globally (--global) or locally (--local). Global aliases are available across all your repositories, while local aliases are specific to a single repository.:

git config --global status

The command above creates an alias st for status keyword so that you can use a shorhand version of the command: git st instead of git status, dead simple.

The created alias is added globally as a key-value pair in the .gitconfig file and to view the file, you can run:

git config --global --list

You can also manually type in aliases directly into the .gitconfig file. Run the command below to open the file in your terminal:

git config --global --edit

The output will look something like this:

  name = syntax-punk

  defaultBranch = main

  st = status

And as you can see, the previously added st alias sits under the "[alias]" declaration, so if you want to add more aliases, you can just add them below the existing ones.

My aliases

  • adog: log --all --decorate --oneline --graph - Displays your commit history in a nice and compact way. Usage: git adog

  • cob: checkout -b - Create a new branch and switch to it. Usage: git cob my-new-branch

  • wip: commit -am "WIP" - Add all changes and commit with a "WIP" message. Usage: git wip

  • undo: reset --soft HEAD~1 - Undo the last commit and keep the changes staged. Usage: git undo

  • hdr: "!f(){ git checkout main && git pull && git checkout - && git rebase main; };f" - hdr aka "hydrate", hydrates the feature branch that you're currently working on with changes in the main branch in remote repository. The command switches to your main branch, pulls latest changes from repository, switches back and then rebases your feature branch on top of main. Usage: git hdr

  • rimbr: "!git checkout main && git branch | grep -v "main" | xargs git branch -D" - rimbr aka "remove branch", it deletes all branches except the main branch. Usage: git rimbr

And that's about it, give these guys a go, but use them responsibly and I hope I could save you a some keystrokes.

Have a great one!