Locked learning resources

Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Locked learning resources

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Tracking File Changes

00:00 Now that you have a Git repo, it’s time to start putting it to use. Now, remember that Git is a version control system, which means you can use Git to keep track of how your files evolve inside a project through time.

00:14 So you’re going to build a history of the evolution of your project. And the data points that make up this history are called commits. And you can think of these commits as snapshots at a particular time of what your project looked like in terms of files.

00:32 So you need to learn how to make commits. In order to do that, start by opening your favorite IDE and create a new file and type in some code like, for example, prnt("Hello, world!").

00:46 If you’re eagle-eyed, you might have noticed that the built-in print() was mistyped on purpose. Let’s play along for a second and pretend you didn’t see that so that later on you have to fix this mistake.

00:59 And then save it as myscript.py. So now you have a code file. And let’s imagine for a second that this is an integral part of your project. So now what you want to do is you want to tell Git that this file is part of your project and that you want the history of your project to reflect the changes to this file.

01:20 How do you do that? If you go back to your terminal, you can run a command called git status that asks what’s the status of your current repo.

01:31 And you can find in the Git output, more or less in the middle, there’s going to be a section that says “Untracked files.” And this section is going to list all the files that Git sees in your repo, but that aren’t being tracked yet.

01:47 So Git acknowledges the existence of the file myscript.py while also telling you, hey, this file isn’t being tracked. It will not show up in the history of the project.

01:57 And Git even adds a suggestion of how to make sure that Git starts tracking this file. If you look under it, it’s going to say use git add <file> to include in what will be committed.

02:10 So that’s precisely what you need to run. If you type git add myscript.py, you’re adding the file myscript.py to the staging area.

02:20 So if you run that, there should be no output. And if you run git status again, the output will be slightly different. This time, the file myscript.py is listed under a section that says “Changes to be committed.”

02:35 So the changes haven’t been committed yet. You haven’t created a snapshot of what your project looks like at this point in time. You just said, hey, this file myscript.py, I want Git to track it.

02:48 And this is the staging area. It’s an intermediate area to which you can add multiple files so that you can review the files that you’re about to commit before making the actual commit.

02:59 So once you’re happy adding your new script to the staging area with the command git add, you can move on to the next lesson where you’ll learn how to make the commit.

Become a Member to join the conversation.