Loading...

Useful Git Aliases That Ease Your Life

Productivity
July 24, 2019
2 minutes to read
Share this post:

When you work with git you can define aliases to make your experience even more productive and elegant. In this short post I’d like to present aliases that I use frequently and how they work. And I’ll start with my favorite: git recent-branches.

Recent Branches

git recent-branches

This command gives you the following output:

This command shows you all branches you recently worked on. That solves the usual problem of me forgetting the names of the branches I worked on.

The alias is the following:

recent-branches = for-each-ref --sort=-committerdate refs/heads/ --count=15 --format='%(HEAD) %(color:yellow)%(refname:short)%(color:reset) - %(contents:subject) - %(authorname) (%(color:green)%(committerdate:relative)%(color:reset))'

Daily

git daily

This is a very useful alias. It’ll display all commits from the last 24h. This is the command to execute right before your daily standup to remind you of what you worked on the last day.

This is the alias:

daily = log --since '1 day ago' --oneline --author [your e-mail]

Graph

git graph

The default git log --graph command is not very clear and therefore I configured an alias which gives a simple overview of all commits and branches.

In the end the alias is simply a sophisticated version git log:

graph = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative

Skip & Unskip

This is not one alias but actually three of them. Sometimes you have files in the directories of your repository that don’t belong in there, but it is also not appropriate to add them to the .gitignore. In this case you can tell git to ignore these files and don’t put them into the worktree. By doing so you can’t stage them by accident.

The aliases are the following three:

git skip [file] // Removes the files from the worktree until you "unskip" them again
git unskip [file] // Adds the files again, so you can stage them
git list-skipped // Lists all files that you skipped previously

The aliases for these are the following:

skip = update-index --skip-worktree
unskip = update-index --no-skip-worktree
list-skipped = ! git ls-files -v | grep ^S

Have you heard of Marcus' Backend Newsletter?

New ideas. Twice a week!
Top