Skip to main content
  1. Posts/

5 BEST Git Commands

·537 words·3 mins
Jake Roggenbuck
Author
Jake Roggenbuck
I am currently studying Computer Science

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!

Here is the post on my dev.to page.

If you have a favorite command of your own, please share in the comments! I’ll highlight my favorite ones!

1. Git List (GLS) #

Git List Command

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) #

Git Logg Command

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 #

Git diff before

After #

Git diff 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!