If there is one fundamental concept that you need to understand is how git manages its files and the stages it goes through as you work on them.
This movement between stages is called the file status life lifecycle and here’s how it works.
Git File Status Lifecycle
As you can see here, there are 4 faces a file can go through when they are contained in a directory managed by git.
Depending on the work you’re doing on them, the files can go through each of these phases many times.
Let’s review each status.
01 Untracked status
When you first create a file in a git folder the file is assigned and untracked status.
This means that git is not actively watching this file, it will be ignored if any changes
There are some files that we want to live on track in a project for example temporary files or setting files.
We can tell git to ignore specific files or file patterns using a special file called get ignore, which we will look at later in the course.
02 Tracked Status
When a file is added to the repository it will enter in tracked status.
From this point on until you change the status to on untraced git will be watching this file actively, and any changes you make to it will be noted.
03 Modified status
A tracked file that changes is marked by git to be on a modified status.
This means that the file has spending charges that need to be completed at some point.
in a way, this is considered an unstable or dirty state because at some point the file changes need to be completed and moved to the next phase.
04 staged status
A file is on a staged status when their work has been completed and is ready to be included on the next snapshot that will be taking off that project.
These snapshots are called commits.
Visualizing Workflow OF gIT FILE STATUS LIFECYCLE
Now don’t worry if you don’t understand all of these stages immediately.
Just try to picture the workflow with an actual file that we’re working on.
First, we’ll create a file in a directory that has been initialized as a git project.
When a file is first created git is not watching it as it’s on an untracked status.
For git to start watching this file we have to issue a command that will move it to Tracked status. The command is called
Once the file is being tracked any changes to it will be detected by git.
Let’s say that now we start working on that file and we do some changes to it. Once we save the file it will mark with a modified status.
We cannot change the files that will be included in the next commit.
Once we finished working on all the files we need and we’re ready to save a snapshot
We will issue a
git add command once again. This puts the file or files into the staged status.
At this point we’re confident the work is ready to go out, either will push it to a production environment or we want all the developers to check our work.
And, we finally issue the
git commit command.
It will take all the files back to the tracked status, ready to begin the whole process again.
Finally if for some reason you elect to Untrack the file, it will fall back in the Untracked status.
This would also be the case if you delete the file.