DEV Community

Cover image for πŸ”± Git Commands You Didn't Know

πŸ”± Git Commands You Didn't Know

Ephraim Atta-Duncan on September 23, 2020

TL;DR One of my favorite things about Git is being as simple as it is and also being customisable and one of those features is aliases. ...
Collapse
 
eljayadobe profile image
Eljay-Adobe

My aliases:

st = status -s -uno
co = checkout
coffee = "!f(){ if [ `date -j +%a` = 'Fri' ]; then echo 'Friday! Time for beer!'; else echo 'Time for a coffee break. Go get a cup of joe.'; fi };f"
master = checkout master
rmbr = "!f(){ git branch -d \"${1}\"; git push origin --delete \"${1}\"; };f"
mkbr = "!f(){ local args=\"$*\"; local gituser=$(git config user.email); gituser=${gituser%@*}; if [ \"$args\" = \"\" ]; then args=\"$(date \"+%Y-%b-%d\")\"; fi; args=${gituser:-${USER}}/$args; args=$(echo \"$args\" | tr ' [A-Z]' '_[a-z]'); git checkout -b \"$args\"; };f"
ls = "!f(){ if [ -z \"${1}\" ]; then echo 'git ls [HASH] β€’ show the files involved in the commit'; else git diff --name-only \"${1}^..${1}\"; fi; };f"
at = rev-parse --abbrev-ref HEAD
unstage = restore --staged
unadd = restore --staged
discard = checkout --
alias = config --get-regexp ^alias\\.
d = difftool
ds = difftool --staged
branches = branch --all

git ls hash
β€” is useful to show the files involved in a commit.

Collapse
 
dephraiim profile image
Ephraim Atta-Duncan

I must say, they are pretty awesome.

Collapse
 
catriel profile image
Catriel Lopez

Grep stands for "Global Regular Expression Printer". It gives you a clue about how it works, which is important, but "git search" doesn't.

I really like the plg and zip aliases, so I'm definitively stealing those! Thanks for writing!

Collapse
 
bloodgain profile image
Cliff • Edited

That's more of a backronym, really. It actually comes from the relatively ancient ed line editor's command g/re/p which basically means "global search / for a regular expression / print matching lines". So it's at least a fairly accurate backronym to the source.

The g command still sort of lives on in vi/Vim's ex mode commands. The most common use these days is probably for g/pattern/d, which does a global search for the pattern and deletes matching lines, sort of the opposite of the original g/re/p command.

Collapse
 
catriel profile image
Catriel Lopez

Oh, I didn't know that! Thanks!

Collapse
 
dephraiim profile image
Ephraim Atta-Duncan

Thanks for grep too. I guess search isn't

Collapse
 
winstonpuckett profile image
Winston Puckett

Oh man. That git here. Where has that been all my life?

Collapse
 
eabase profile image
eabase

Nice one there Ephraim.
Been using git for years, and still found something useful here.
PS. "grep" is selecting something using regular expressions.

Collapse
 
dephraiim profile image
Ephraim Atta-Duncan

Wow. Thanks

Collapse
 
goodevilgenius profile image
Dan Jones

en.wikipedia.org/wiki/Grep

Read a bit more about standalone grep. It's an important part of any unix system.

Collapse
 
0xwdg profile image
Wesley de Groot

My favorite is git recommit.

Collapse
 
srepollock profile image
Spencer Pollock • Edited

This one is my current favorite. Highly recommended after a git fetch --all to visualize where the branches are at.

[alias]
    tree = log --graph --oneline --all
Collapse
 
ankitbeniwal profile image
Ankit Beniwal

Now I will have the proof in order to blame someone for a bug. πŸ˜‚πŸ˜‚

Cool.

Collapse
 
dephraiim profile image
Ephraim Atta-Duncan

πŸ˜€

Collapse
 
gusdecool profile image
Budi Arsana

My only and must have alias git up

alias.up=pull --all --prune

It fetch all branches, delete tracking remote branches that not exist and pull the update.

Collapse
 
dephraiim profile image
Ephraim Atta-Duncan

Nice.

Collapse
 
dsbarnes profile image
dsbarnes

I learned of git cherry-pick top of last week, thought I'd toss that one in here too.
Great article!

Collapse
 
picwellwisher12pk profile image
Amir Hameed

waow. nice

Collapse
 
keefdrive profile image
Keerthi

nice ...thanks for sharing

Collapse
 
tcelestino profile image
Tiago Celestino

Nice!! I’ll update my .gitconfig now!!

Collapse
 
pollobatgit profile image
Ashiqul

Some names are creative. Nice read. πŸ‘

Collapse
 
dephraiim profile image
Ephraim Atta-Duncan

Thanks