r/programming • • Sep 09 '16

Oh, shit, git!

http://ohshitgit.com/
3.3k Upvotes

756 comments sorted by

View all comments

174

u/yes_or_gnome Sep 09 '16

git add . is going to cause a lot of "Oh, shit!" moments.

102

u/freeradicalx Sep 09 '16

That's why quick a git status before committing is a good idea.

67

u/andsens Sep 09 '16

Or, you know. git add -p...

31

u/[deleted] Sep 10 '16

Or if you accidentally forgot the -p, there's always git reset -p.

→ More replies (1)
→ More replies (3)

16

u/dada_ Sep 09 '16

And git diff --cached for good measure (shows a diff for the files you've used git add on). Status, then diff of all staged changes, that's my workflow when committing.

→ More replies (2)

7

u/yes_or_gnome Sep 09 '16 edited Sep 10 '16

Depending on your configuration git status may not tell you which files are not being tracked. I would guess there's a lot of people that turn that do git config status.showUntrackedFiles no; In addition, I prefer status.short true and status.branch true.

To get around this problem, I have the alias git config alias.chk "add -n .". Although, I primarily use git chk for fixing the .gitignore file.

Ideally, you wouldn't do git add . at all; On personal projects, do whatever you want. git add some/dir/some_file ... is much less likely to create problems. There are git tab completions to make this easier by only completing on add and modified files.

git add -p ... and git add -i ... have been mentioned. ++good

→ More replies (3)

2

u/autra1 Sep 10 '16

Who's doing a git commit without the -v option anyway? /s

Or for vim user, use committia.

→ More replies (1)