This article is a description of all the basic git add commands.
Git uses a notion of changes staged for the next commit where you set which change you wish to include in the next
git commit command. This includes new files, deleted files and modifications.
For those in a hurry, here is the conclusion of this article:
|Command||New Files||Modified Files||Deleted Files|
Let’s start by initializing a new git repository:
git add [<pathspec>…] to add file by their name.
If we want to add our two files created above:
It is also possible to use wildcards
After any of these two commands, both our files will be staged for the next commit. Let’s do our first commit before we continue.
If you wish to add deletions, updates and file creations, you can use any of these 3 commands:
git add -A
git add .
git add --all
At this point, any of the command above will stage all these files:
At this point, let’s do a
git reset to revert the staged changes and demonstrate the other commands.
If you don’t want to add the newly created files, but only the modifications and deletions, use any of the following:
git add -u
git add -update
Once again, a quick
git reset will reset staged changes and allow us to look at the last option
If you want to stage everything except the files that have been deleted, use:
Here is the full script if you want to see it with your own eyes :)
Hope this gives you a clearer view of what is going on !