DEV Community

Cover image for Git Commands Cheat Sheet

Git Commands Cheat Sheet

Madhav Ganesan on June 18, 2024

Git is a distributed version control system (DVCS) that allows multiple developers to collaborate on a project, tracking changes to files and coord...
Collapse
 
syedmuhammadaliraza profile image
Syed Muhammad Ali Raza

for reset here is 2 commands

git reset --hard HEAD^

git reset --soft HEAD^

Collapse
 
madgan95 profile image
Madhav Ganesan

Can you explain the use of these commands?

Collapse
 
syedmuhammadaliraza profile image
Syed Muhammad Ali Raza
  • git reset --hard HEAD^: Moves the current branch to the previous commit, discarding all changes in the working directory and index.
  • git reset --soft HEAD^: Moves the current branch to the previous commit, keeping changes in the index and working directory.
Thread Thread
 
madgan95 profile image
Madhav Ganesan

Thanks Syed👌

Thread Thread
 
madgan95 profile image
Madhav Ganesan

I have added them in the blog👍

Thread Thread
 
syedmuhammadaliraza profile image
Syed Muhammad Ali Raza

👍

Collapse
 
pioche profile image
Ridwan Yunus

He gave you food you still want him to feed you.

How about you make your own research on their functions?

Collapse
 
gregjacobs profile image
Greg • Edited

You’ve got your Resets backwards.

Where you say “Soft reset:” you are displaying the git command for HARD.

Where you say “Hard reset:” you are displaying the git command for SOFT.

Should be…

Soft reset:
git reset --soft HEAD^

Hard reset:
git reset --hard HEAD^
Enter fullscreen mode Exit fullscreen mode
Collapse
 
madgan95 profile image
Madhav Ganesan

Thanks for pointing out. Changed👍

Collapse
 
andre75021 profile image
Andre Luiz

Great post, so much usefull

Collapse
 
madgan95 profile image
Madhav Ganesan

Thank you so much! I'm glad you found it useful😊

Collapse
 
andre75021 profile image
Andre Luiz

You're welcome!!

Collapse
 
jgdevelops profile image
Julian Gaston

Classic post.

Collapse
 
madgan95 profile image
Madhav Ganesan

Thank you Julian🫡

Collapse
 
litlyx profile image
Antonio | CEO at Litlyx.com

Pretty usefull. Thanks for sharing!

Collapse
 
madgan95 profile image
Madhav Ganesan

Thank you 😊

Collapse
 
qui profile image
qui • Edited

You said origin but it may another thing.

Collapse
 
madgan95 profile image
Madhav Ganesan

Yes, but when we clone a repository, the remote name by default is origin unless we change them explicitly.👍

Collapse
 
qui profile image
qui

Yes you're right but I think you should explain it.

Have a good day. :)