Each of the files in the working directory are in one of two high-level states:

tracked files – These are files that were in the last snapshot (aka); they can be in one of the following sub states:

unmodified – These are any files that haven’t been modified since the last commit. They will still be included in the next commit, but remain as is.

modified – These are files that have been modified since the last commit (we probably modified these as part of bug fixes). These files will be included in the next commit, but will be included in thier respective new form.

staged – These are files that are either not present in the last commit (e.g. newly created files) or are “modified” files that we tell git to include in the next commit. Files are added to the staging using git’s “add” command.

untracked files – these are any files that are not being tracked, i.e. git isn’t of the existance of these files. You can change the state of these files to “tracked – staged” by using git’s “add” command

In the case of cloning an exisiting git repo

Now if you clone a git repo, then all the project files start off in the “unmodified” state

At this stage, if you do a git “commit”, the edited file will not get committed, that’s because modified files first needs to be “staged” in order to be included in the next commit. This is done using git’s “add” command:

After that, once you are happy with everything, you then take a snapshot using git’s “commit” command. This results in the files from the previous commit being overlayed with the newly staged files in order to create a new snapshot (aka commit).

You then repeat the cycle again.

Another thing you may want to do is remove a tracked file from the project. This is done using git’s rm command:

Note, at this point, our commit is only stored on our local workstation. We need to do a git "push" to get our commit uploaded.

Tips:

There will be times when you have a lot of modified files that you want staged. In which case, it can get tedious to stage them one-by-one. However you can use the following to stage all modified files:

git add -u

If you want to stage all modified files as well as all untracked files, then do:

git add -A

Note, this command will also factor in any tracked files that have been set to untracked too.

Note, there isn't any obvious way to only stage new files and ignore any modified files.

In the case of creating a new git repo

With the new git repo, there are no commits to begin with. Hence all exisitng/newly-written project files start out as untracked files. We then use the "add" command to tracked-staged them, before we do the commit.