Well, sort of. I’m just going to be explicit on the offchange there’s a misunderstanding.
So: initially, files aren’t tracked by git. If, in a git repository with one file that I’m not tracking, I type git status, I get this:
> git status
On branch master
Initial commit
Untracked files:
(use "git add <file>..." to include in what will be committed)
text.md
So: let’s add it:
> git add text.md
> git status
On branch master
Initial commit
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: text.md
OK, so that file is now going to be tracked as a new file. It’s not commited yet - it will be added when I commit:
> git commit -m "First commit."
[master (root-commit) 2c0836a] First commit.
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 text.md
Now, if I alter that file, and then look at the status:
> git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: text.md
no changes added to commit (use "git add" and/or "git commit -a")
So: the file is modified, and because git is tracking it, it’s picked up automatically. But: if I do a commit, nothing will be added. You have to add the file to the current index in order for it to be committed. Say there’s another file I’ve also altered in there, called moretext.md:
> git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: moretext.md
modified: text.md
no changes added to commit (use "git add" and/or "git commit -a")
They’re both marked as modified. I want to commit the changes to text.md, but not the ones to moretext.md. I’d add one, but not the other:
> git add text.md
> git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: text.md
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: moretext.md
Can you see? The file I’ve added is going to be staged for commit; the file I haven’t won’t. If I do a git commit now, only one file will go out.
This is also true of the GUI versions: you don’t automatically commit everything you’ve altered, unless you want to. You choose precisely what goes into each commit.
Now, having made your way through all that terminal guff, here’s the really useful metaphor: I like to think of the working index as a dumb waiter. I have all this food kicking around, but I only want the stuff I’ve finished to go up. So I stage it all, using git add, onto the dumb waiter, and then my commit sends only that out.
The initial add adds a file to be tracked and stages it; future adds are just staging those changes.