Let's Create Code

Sign in to track progress
5:44

Chapter 2: Versioning

This module will cover the most essential concept to Git: versioning code.

This chapter is a continuation of the “Use Case 1: Capturing Changes” section in the previous chapter. If you happened to have skipped over that section, I strongly recommend reading it before proceeding.

In this chapter, we will be learning these core skills:

  1. Creating sample files using a CLI (setting up a new project).
  2. Telling Git about the existence of those files (initializing Git).
  3. Making and capturing changes to those files (Commits).

Before we start, ensure you understand the terminology below. Some readers are new to programming and may not understand these:

Next, here is a handy cheatsheet of the CLI commands we will be using in the forthcoming sections:

| For advanced students: if you ever want to read up on what a command does, you can type “man <command>”. “Man” stands for “manual”, which allows you to read the documentation on that command. Give it a try!

Finally, here is a cheatsheet of the Git commands we will be learning in this chapter:

Setting Up Our Project

To try out Git, let’s first create some files with text in them. To keep things simple, we will not be adding actual code.

| Note: if you are using Windows to follow along, ensure you are using the Git Bash application, as explained in Chapter 1 regarding Git installation, so that these commands work.

Ok, let's get started!

We can use the default directory that we are placed in when the terminal opens.

Now, create a new directory called “closet”:

mkdir closet  

We’ve named this “closet” because this is where we will store (and version) different things that will go inside of an imaginary closet. We’ll be adding text to different files that includes names of different types of clothing.

`mkdir <directory name>` here stands for "make directory".

Now navigate to the `closet` directory:

cd closet  

"cd" stands for "change directory", which allows us to navigate to the respective directory.

Let’s place our first file into this directory. Run the following command to add some text to a new file, README.md:

echo "A project to help us learn Git." > README.md  

The `echo <text>` command here simply prints back the text you've entered.

The ">" symbol here takes that text and injects it into a new file, in this case, `README.md`.

The `.md` file type stands for "Markdown" and is similar to a `.txt` file that you are probably already familiar with, except it can include special formatting.

| Note: since this course covers as realistic examples as appropriate, note that "README.md" is a common file that is typically contained in a code project. It typically will contain a high level overview of the project as well as useful commands for first-time use (i.e. “read me first if you're new to this project!”).

You should see the following printed to the screen:

A project to help us learn Git.  

Now, let’s list all the files in our directory and confirm no other files are here:

ls  

“ls” stands for list files.

You should only see:

README.md  

You shouldn’t see any other files.

Now let’s confirm the contents of the file are in there:

cat README.md  

You should see the contents of the file printed out to the screen.

Perfect, now we have a starter file which represents our new project and we are ready to version our code. We'll do this in the next lesson.