Getting Git

A comprehensive video course from git init to Git Master.

Master: git status


In this video we'll Master the status of git status.

We covered the basic output of git status in init: git status.

Not, let's take a look at the different states of changes.

Having a fundamental understanding of these states will help you Master Git.

Let's demonstrate each of the states by reviewing the output of git status as make changes.

If we run git status, we see we're in the same state as we were at the end of the init video.

We have changes ready to be committed and one untracked file.

We'll start with the untracked file.

When a file is untracked, it means it is not under version control. This means, Git does not track any changes made to this file over time.

To emphasize this, let's record our current changes to be committed with git commit and run git status.

The file is still listed as untracked and was not recorded in our commit.

In addition, we can make changes to this file and Git still lists the file as untracked.

We can add this file to our Git repository and start tracking it's changes with git add.

Let's add it and run git status again.

We see the file is now under changes to be committed and, like before, run git commit to record the changes.

If we run git status now, we see we are in a clean state. This means there are no untracked files and all tracked files are unmodified.

So, let's modify one of our tracked files and run git status.

We now see the file listed as modified. Since this file is under version control, Git will track any changes to the file from the previous commit.

Let's run git add -p to review these changes. Git sees the two new lines I added, so I'll say y to add the changes.

If we run git status again, we'll see the changes are now ready to be committed.

Changes to be committed are considered staged. This is the final state in the change lifecycle.

Once we run git commit, all staged changes will be recorded which resets their state back to unmodified.

So to quickly review the change lifecycle,

A file starts as untracked, when we run git add, it becomes staged. When we run git commit, it becomes unmodified. When we change a tracked file, it becomes modified. When we run git add, it becomes staged. When we run git commit, it becomes unmodified. And the lifecyle repeats.

While most of the time you'll be promoting changes up through this lifecycle, remember, git reset can be used to demote changes down the lifecyle.

Finally, you may be wondering what to do with a file you don't want to track. I'll cover how to ignore files within a Git repository in Everyday Git.