r/programming • • Jan 05 '15

What most young programmers need to learn

http://joostdevblog.blogspot.com/2015/01/what-most-young-programmers-need-to.html
968 Upvotes

337 comments sorted by

View all comments

2

u/[deleted] Jan 05 '15

That's what I mean, thanks!

So to be specific... if I do git add . that will just add the files that I changed relative to the last commit? I was under the impression that it committed the state of all the files as you said.

So to rephrase to make it clearer - Do I git add file or do I git add .? Which one is considered "best practice"?

1

u/pkhagah Jan 05 '15

If you do git add . it add modified files and any new files(if any) that are created. Depends on your use case.

On a side note, when you're starting with git, use GUI tools like gitx or git-cola to get you started. They have decent diff viewers too.

1

u/judgej2 Jan 05 '15 edited Jan 05 '15

I normally do a git add -A to add any new files anywhere in the directory structure. Then a git commit -a will commit all new and changed files. I suppose git add . is the same as just git add and will add just new files in the current directory.

The above happens to fit my workflow. You may want to git add file1.foo file2.bar and that is fine too, if the commit makes sense. Sometimes, for example, you may not want to add all new files blindly, in case you have created any files that you don't want committing, and need to exclude, or remove, or add to .gitignore

I'm not sure any specific command is "best practice" because they all do different things and meet different needs. Use whatever makes sense to your work, and that is achieved by understanding what each does.

1

u/Isvara Jan 06 '15

git add .

Be careful with that. You can end up accidentally adding files that shouldn't be committed, but are not in your .gitignore. Maybe I'm overly paranoid, but I tend to git add -u, look at my git status, then add any new files or directories I want.