DEV Community

Essential git commands every developer should know

Dhruv on September 28, 2017

If you’re one of those developers who still don’t use any version control system, I don’t know how you’re still managing to get work done. In this ...
Collapse
 
andy profile image
Andy Zhao (he/him)

Definitely git add -p too, for an interactive view of what you've made changes on.

Collapse
 
leomeloxp profile image
Leo Melo

This! git add -p was probably was helped me the most when swapping Source Tree for CLI git.

Collapse
 
loujaybee profile image
Lou (🚀 Open Up The Cloud ☁️)

Always git add -p !

Collapse
 
ratraze_54 profile image
ratraze

I think rebase is one thing that should be present in this list.
Personally, I use it quite often and it's really helpful, especially if you work in a team.

And interactive rebase allow to squash commits and keep your history clean and clear.

Collapse
 
garrincha_7 profile image
Benoit Goepfert

Totally agree, I use it so often I can't even imagine working without it now.

Collapse
 
tensaga profile image
TENsaga

Definitely! Extremely useful.

Collapse
 
hkly profile image
hkly

Also git diff, I use this all the time to review changes before committing them.

Collapse
 
leomeloxp profile image
Leo Melo

git log --graph if you want to see the classic git branch timeline view.

git log takes has a huge number of options, I normally use it with:

git log --color --oneline --decorate=no --graph
Enter fullscreen mode Exit fullscreen mode

Optionally I also passing --all in case I want to see all branches.

Collapse
 
virup profile image
Viru • Edited
Collapse
 
arvinderakgp profile image
Arvind Gupta

At Point 10). You can also use "git stash pop" for getting back locally save code.

for your reference find the difference between "git stash apply" and "git stash pop" in below link

stackoverflow.com/questions/152860...

Collapse
 
dimanjan profile image
Dimanjan

Also , Search

Search the working directory for foo():

git grep "foo()"
Collapse
 
k4ml profile image
Kamal Mustafa

To see history of changes at specific line:-

git blame -L337,+5 -- src/myproject/services.py

To see evolution at line 337:-

git log --pretty=short -u -L 337,337:src/myproject/services.py
Collapse
 
techgeekbuzz profile image
Techgeekbuzz

Hi Dhruv,

You have shared a nice list of Git Commands, I have shared my own GIT Commands List Please check, if you find anything which is missing from your list, please add them into your websites: techgeekbuzz.com/git-commands/

Collapse
 
thomaswdmelville profile image
Thomas Melville

I would replace merge with rebase, but that's just me :-)

Collapse
 
profplum profile image
profPlum

Definitely git bisect too, I though the idea of commits were cool but was really skeptical of the practicality of using them to debug. git bisect stream lines this very efficiently and is an incredibly useful debugging tool!

Collapse
 
lauragift21 profile image
Gift Egwuenu

i'll add git reflog

Collapse
 
sadavarti profile image
Vikas Goyal

try tig utility, it shows logs in interactive way.

Collapse
 
twostepdeveloper profile image
twostepdeveloper

amazing post

Collapse
 
itsjzt profile image
Saurabh Sharma

A handful of great git commands wesbos.com/git-hot-tips/

Collapse
 
maytrovato profile image
Adrián González

How about git commit --interactive ?

Collapse
 
mister_frostee profile image
Mister Frostee

Consider better formatting to improve readability. Give examples with fake names or paths.