These are the top 5 most useful git commands that I use almost every day. Out of the 30+ git command aliases I have, these are the for sure the best 5! Please let me know in the comments which ones you like the best!
If you have a favorite command of your own, please share in the comments! I'll highlight my favorite ones!
1. Git List (GLS)
View a super short summary of the most recent commits. Instead of filling the page with just a few commits, view each commit in a single line.
git log --pretty=oneline --abbrev-commit
I have this aliased to gls
with
alias gls='git log --pretty=oneline --abbrev-commit'
2. Push Origin (PUSHO)
Push to the current default branch. This one is simple, but I use this one the most.
git push origin $(git symbolic-ref --short HEAD)
I have this aliases to pusho
in my .bashrc with
alias pusho='git push origin $(git symbolic-ref --short HEAD)'
3. Git logg (LOGG)
View an ascii art history of all of the branches.
git log --graph --decorate --all
I have this aliased to logg
with
alias logg='git log --graph --decorate --all'
4. Git Diff Precise (GDP)
Have you ever been looking at a git diff and it just tells you the whole line is different? Well, this command tells you exactly what characters have changed. Extremely helpful for catching issues in review or remembering exactly what you changed in a large line.
Before
After
This is a simple example and it's easy to see what has changed, but if you had a really complicated line with a few different changes in different places, it can be hard to catch. Say an SQL command or similar.
Here is how to do it!
git diff --word-diff=color --word-diff-regex=.
I have this aliased to gdp
with
alias gdp='git diff --word-diff=color --word-diff-regex=.'
5. The MOST useful of all (lookz)
Have you ever tried looking through a whole git history to try to find where you added or removed something? Has a line gone missing or a type changed that has caused an issue in production that you need to fix ASAP! Looking through each commit for a single line may take hours with a big repository. This allows you to search through every commit and use FZF to do it.
This does require you to have fzf installed, but I recommend having that anyway. It's super useful for this type of thing.
git remote && git log --pretty=oneline --abbrev-commit \
| awk '{print $1}' \
| xargs -I {} git show {} | fzf
I have this aliased to lookz
with
alias lookz='git remote && git log --pretty=oneline --abbrev-commit | awk '"'"'{print $1}'"'"' | xargs -I {} git show {} | fzf'
Note the single quotes having to be escaped with '"'"'
in the bash alias version but not the one directly for the shell.
I need help making this command more useful. It lets you find a specific name of something that can then be used to search, but once it's selected, you can't find the commit. If anyone knows how to do this, please leave a comment!
Top comments (5)
I have
git poh
for pushing HEAD to my origin, which is an alias for...git push origin HEAD
, you don't need to do magic to resolve HEAD. Git does that for you, equally nice:git po
isgit push origin
andgit po HEAD:foo
pushes the current branch to the remote foo branch.My favorite (aliases) are:
I really like the
GDP
alias, will definitely be using that one myself.Amazing post !!! I liked new commands.
What does BEST acronym actually stand for?
and
lookz
didn't not knew yet either 🤔 🤔?Isn't lookz just another git blame?
Some comments may only be visible to logged-in visitors. Sign in to view all comments.