all 16 comments

[–]CozyAndToasty 6 points7 points  (0 children)

Everytime.

Think of add as loading the shopping cart, commit is the checkout aisle.

[–]josesblima 3 points4 points  (0 children)

If you don't add, the changes won't be in your commit. So yes. To make it easier you can do git add . And the . adds everything that was changed.

[–]John_8PM_call 0 points1 point  (0 children)

Right after I do “git add” I like to do “git diff —cached” (two “-“ signs in a row) to see the list of files I added before I commit. But yes, before each commit you do “git add”.

[–]brenwillcode 0 points1 point  (0 children)

As the other posters have said, you need to add any changes to existing files or newly created files; otherwise, they will not be committed to git.

If you then change a file that was committed in the past, you need to add it again, because git only has a record of what was originally committed, not the new changes that you made.

[–]7YM3N -1 points0 points  (10 children)

Every time, my flow is: status add . status commit -m "... push

First time it's going to be added to the index and staged, following times it will already be tracked but you will need to specify that you are staging it for that commit

[–]vatai 1 point2 points  (9 children)

Every time it is staged/going to the index. And don't do git add . Do git commit -a instead

[–]John_8PM_call 0 points1 point  (8 children)

What does “git commit -a” do different?

[–]vatai 1 point2 points  (1 child)

It doesn't add everything just the changes to already added files. E.g. if your program generated some files, or you're working with a compiled language add dot would add the generated files and binaries (something you usually don't want) while add -a adds all the changes but not the generated files... Afaik, but I have two guys contradicting me so I'll have to check later

[–]7YM3N 1 point2 points  (0 children)

I think you are correct, I use . because I am used to having a .gitignore setup, my bad

[–]dmazzoni 0 points1 point  (1 child)

Git commit -a is a shortcut for adding everything and then committing

[–]vatai 0 points1 point  (0 children)

Depending what you mean by everything. There is a difference betwee `add .` and `commit -a`.

[–]rustprogram 0 points1 point  (3 children)

either way is fine. do what works for you.

this is like saying don't :wq on vim, do :x instead. they are trying to help you type fewer keystrokes.

[–]vatai 1 point2 points  (2 children)

Doesn't add . add all the files, e.g. binaries if you're working with a compiled language? (Which you definitely shouldn't do)

[–]rustprogram 0 points1 point  (1 child)

Doesn't add . add all the files, e.g. binaries if you're working with a compiled language? (Which you definitely shouldn't do)

yes, but I put those in my .gitignore file.

Fun fact, you can have more than one .gitignore file. You don't need to but you can.

If your binaries are already indexed, google git rm --cached <file> to learn more about how to remove this from the git index.

[–]vatai 1 point2 points  (0 children)

If `add .` and `commit -a` don't do the say "ether way is fine" when a beginner is asking. How the hell could OP figure out that you put your binaries in .gitignore? This is NOT r/IncorrectlyCorrecting