How to Add Files Into Staging by Git in Different Ways
While the command git add
might be the most frequently used command to add files into staging, other flags might come in handy depending on the situation. This article dives deep into the flag you can utilize with the git add
command.
Flags for git add
in Git Version 2.x
The different modes of git add
can be illustrated in the table below.
Command | New Files | Modified Files | Deleted Files |
---|---|---|---|
git add -A <optional_path> |
✅ | ✅ | ✅ |
git add . |
✅ | ✅ | ✅ |
git add --ignore-removal . |
✅ | ✅ | ❌ |
git add -u |
❌ | ✅ | ✅ |
The first two commands, git add -A
and git add .
functions similarly as both are used to stage all the files (new
, modified
, deleted
). Furthermore, the command git add -A
is equivalent to git add -all
. The only difference between these two commands is that git add .
adds all files in the current folder and if git add -A
is run without specifying the path. It will add all the files into the staging irrespective to the directory you ran the command from.
The third flag works quite differently, as it adds just new and modified files only to the staging, while the last command, git add -u
stages modified and deleted files only. The long-form of git add -u
is git add --update
.