But some things make the usage of Git difficult for new starters. I would like to highlight one particilar case; how to add files to the index. The approach differs based on the situation. New files, deleted files and already commited files are treated differently. In my opinion Git is missing one command to add all changes to the index including deleted, changed and new files. Even better git should have a commit command which add everything to the index and commits it. Experts may want finer control but in my opinion this missing option makes it hard for new starters.
Perhaps git will add such a feature in the future, in my humble opinion the power of a complex workflow should not be payed with the lack of simplicity.
The following command will add everything to the index except deleted files.
git add .
Unfortunately IMHO there is not “git add .” for removed files. You can not tell git to add all files which are deleted to the index via wildcards. The following will not work, you need to specify the files individually.
git rm .
The starter may think I just use git commit -a to do all this adding and deleting. Unfortunately this will only add deleted files and files which are already commited to the index. New files are not included.
git commit -a -m "message"
If you want always to add your deleted files and as well as stage files what are already commited you should use the following command. This will not add new files to the index. Thanks to Heath Borders for the clarification on this command.
git add -u .
I hope this helps, at least I got stuck for a while in these suble but important differences. Handling this example and much more can be found in my Git Tutorial.
Btw. please don’t get me wrong I like having all these options but in addition to these option I believe git would be easier if it had one “add-it-all” option.
You find me also on Twitter .