DEV Community

Mehran Kader
Mehran Kader

Posted on

Some of git aliases I use to speed up my work

Hi everyone! I have read a lot of articles on git (most of them from dev.to) where many of you shared you git tips and tricks. There were also a few cool ones where the concepts of version controlling and how git actually does these things were mentioned. I am really grateful to the wonderful developer community that just keeps growing! In this post I thought to share some of my git aliases that I use which helps me avoid repetitive commands and also enables to maintain a clean git tree. So here goes!

I have bound this command to "lg", and it shows my git commit history in a nice and easy to read one line format. I've forgotten where I took it from but it's either from stackoverflow or here!

log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
Enter fullscreen mode Exit fullscreen mode

I use rebase a lot to update my feature branches with master. This takes a few commands where I used to update my local master branch and then go back to my feature branch and rebase the updates. There are probably better or different ways to do this, but I just use this since it works without issues! If anyone has any suggestions on this feel free to comment!

!git checkout master && git pull --rebase && git checkout - && git rebase --interactive master

Although I wrote this one on my own but I must thank the writer of this post for putting git rebase in such an easy to understand way!
The Git Rebase Introduction I Wish I'd Had

This one is a niche command that comes in handy sometimes! Basically it reverts the last changes that I did to my git tree (I think :p), and can even revert rebases!

reset --hard ORIG_HEAD

Sometimes I just need to update my last commit with a few new changes. I use this command to do that in a jiff!

commit --amend --no-edit

Ez commits!

!git add -A && git commit -a

Well that's it for this post! These are the git aliases I found most useful in my day to day work. Thanks to everyone in the dev community (from dev.to or not) for all the help that I receive day to day (not just for git!)!

Top comments (0)