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

Making Your First Commit

00:00 The history of a repo is made out of commits, and you make commits by using the command git commit. So in order to make a commit, you can always start by running git status to check that there are changes to be committed.

00:12 If you check the output of git status, there should be a section that says “Changes to be committed,” and you should find there a list with all of the files that you want to commit.

00:22 And once you’re happy with that list, you’re going to type the command git commit.

00:27 Once you press Enter, Git will automatically open an editor that you’re going to use to write a commit message. Now, the commit message is a brief description of the changes that you just committed.

00:39 Because think about it, you’re going to have a project that might grow to thousands of commits, thousands of data points that mark snapshots of your project’s history.

00:48 And so if you just look at the data points, it’s going to be very hard to know what happened at a particular point in time. So you write a commit message, a short summary, a short description of those changes so that it’s easier to navigate the history.

01:01 Now, the editor that is going to be open can vary. By default, it should be an editor called Nano that looks more or less like what you see on the screen. You type an example commit message, and then you use the shortcuts shown at the bottom of the screen to save.

01:17 That’s going to be Ctrl+O. And then you press Enter to confirm that you’re saving the file. And then you press Ctrl+X to exit. Once you exit Nano with a successful commit message, Git will show you the output saying that you were able to make a commit.

01:37 It will show you a short sequence of arbitrary-looking characters. And then your commit message should show in front of it, together with a list of all the changes that you made.

01:50 In this case, it’s a change to a single file. You created a new file. Now, as your project grows and as the history of your project grows, you can run the command git log to take a look at the log of all of your commits.

02:05 So when you press Enter, you’ll see a list with all of your commits. You can navigate this list with the up and down arrows, and then you can press Q to exit.

02:14 Now, note that some of the things that you’ve been doing show up in your log. For example, the second line of output shows Author: and then your name.

02:25 And how can Git know your name? Well, if you remember, you configured it a couple of lessons ago. Same thing for your email address. So this is the identity that Git uses because you configured it to use it.

02:37 Also, the commit message shows up in your Git log. The only thing that’s left to do in this lesson is fixing the commit message because commit messages should be descriptive.

02:49 They shouldn’t be generic. Otherwise, when you navigate your history of commits, you can’t tell what was happening at that time. So you’re going to amend this commit message, and you can do so by typing git commit and then --amend.

03:04 When you press Enter, the editor will open again, and this time you’re going to delete your generic commit message, and you’re going to say, “Created a hello world script.”

03:16 And then you save with Ctrl+O, press Enter to confirm, and then you exit with Ctrl+X. Git will tell you once again that the commit was made, and if you run git log again, you should still see a single commit, but with a much better commit message.

03:34 However, if you run your code, you’ll see that it doesn’t work. So in the next lesson, you’re going to fix your code and learn how to update files that are already being tracked by Git.

Become a Member to join the conversation.