DEV Community

Cover image for 4 Most Common Git Mistakes 😍 🔥

4 Most Common Git Mistakes 😍 🔥

Simc Dev on July 08, 2022

1. Discard changes to local files in git As a programmer, it happens every day that unexpected errors occur. To solve the errors quickly...
Collapse
 
carehart profile image
Charlie Arehart

See the original post, which has far better text (and command) formatting, as well as screenshots, and discusses 7 rather than 4 "Git mistakes" .

Collapse
 
devsimc profile image
Simc Dev

agreed, that original post has better view and explanation....
the original post is also written by me....
I was trying to make series of it...

Collapse
 
chrisjohdev profile image
Chris Johannesson

I wrote a cheat sheet for Git and Github where I used the book that is referenced in the pdf. It's a free book and well worth downloading. You'll find my cheat sheet at: github.com/ChrisJohDev/pub-GitAndG...

Enjoy it's free. ;)

Collapse
 
devsimc profile image
Simc Dev

Nice.!

Collapse
 
crayoncode profile image
crayoncode

Point 1 can also be achieved through git reset --hard HEAD.
git checkout is most handy if you only wish to undo changes in one directory or a specific file by checking out that directory/file again.

Collapse
 
devsimc profile image
Simc Dev

🔥

Collapse
 
devsimc profile image
Simc Dev

🔥

Collapse
 
lazarovbonifacio profile image
Lázaro Vinícius de Oliveira Bonifácio

I think that git config --global <something> is also a mistake. Because, I guess, in most cases we have the company repo and personal repos cloned in the computer. And the configuration of git are usually different in both (user.name and user.email, for example).

Collapse
 
yimiprod profile image
Yimi • Edited

Instead of git checkout - myFile we can use the command git restore myFile which is less ambiguous in and less error prone since it's dedicated to that task.

Collapse
 
devsimc profile image
Simc Dev

🔥

Collapse
 
gnsp profile image
Ganesh Prasad

Point 3 can be done with git rm --cached filename

Collapse
 
devsimc profile image
Simc Dev

🔥

Collapse
 
tsbrun profile image
Anya Brun

These are very helpful 👍🏽 Thanks for the article!

Collapse
 
devsimc profile image
Simc Dev

Thanks

Collapse
 
thec0def0x profile image
CodeFox

Handy tips. Thank you. I’ve become too reliant on Visual Studio Codes source control for unstaging stuff.

Collapse
 
devsimc profile image
Simc Dev

Thanks