Git (recording changes to the repository)

MrArc
2 min readFeb 10, 2022

After you have a git repository that keeps a snapshot of the changes in your working directory, its time to record the changes or commit a snapshot of those changes into your repository each time the project reaches a state you want to record (see getting a git repository if you want to get a project into git or clone an existing project).

Each file in your working directory can be in one of two states; Tracked or Untracked.

Tracked files are files that were in the last snapshot; they can be in three forms namely unmodified, modified, staged.

Untracked files are files in your working directory that were not in your last snapshot and are not in your staging area.

When you first import a project into git (using the command git init in that directory), all the files are marked as untracked.

When you first clone a repository, all your files will be tracked and unmodified because Git just checked them out and you haven’t edited anything.

Git file states lifecycle

The main tool you use to determine the state of your files is the command

git status

This shows you the state of your files in your working directory. example

Tracking new files

If you want to track new files you need to add them to the staging area. you do this with the command

git add <filename>

This command also stages modified files that are already tracked.

If after staging a file to the staging area and you then modify the same file, that file will also be in a modified state.

After your staging area has all the changes you want to save or commit, the command you need to change the state of your files from staged to unmodified (which means your files have not been changed since the last commit) is;

git commit

Doing this launches your editor of choice (you can configure it with whatever you want using git config — global core.editor). the editor is for you to write your commit message. you can use a shortcut to this by typing the command

git commit -m “your message here”

this command does the same as the above but without launching an editor.

--

--