Goal: Follow along with this lesson to see how changes are tracked using Git. We'll create a one-page website that says "hello" to the world. The steps we follow in this lesson will reflect the daily workflow we'll use when coding all of our projects. Use the details in the cheat sheet as reference for starting all of your projects.
In order to save code using the Git version control system, Git must have a name and email to stamp every time we take a snapshot of our work. We do this with a global configuration in the terminal:
$ git config --global user.name "Padma Patil" $ git config --global user.email [email protected]
This sets the name and email for every save that is made in any directory anywhere on the device. If you are setting this on your personal device you will only have to set this once for it to be set on every project.
Whenever we start a new project, we create a new project directory.
If we enter
ls at the prompt, we can see the list of what other files and directories are in our home directory. We need to decide if this is where we want our new project to be stored. If you are on your own device, you may want to create a new directory that stores all of the code you plan to create.
At Epicodus, we will create our project directories in the Desktop directory for easy access. Let's change directories from our home directory into our Desktop using the
$ cd Desktop
Now, we can add our hello-world project directory :
$ mkdir hello-world
ls shows that our hello-world directory was created. This is also mirrored by the new folder on the Desktop of our machines.
Let's change directories again so that we are now in the hello-world directory:
$ cd hello-world
To confirm that we are where we think we are, we can always show our location with a
The next step before we create a single file for our hello-world website is to create a Git directory within our project directory that will track everything we add, modify and delete.
We do this by initializing a new Git repository:
$ git init Initialized empty Git repository in /Users/staff/Desktop/hello-world/.git/
Now if we do an
ls, we might expect to see the new directory. But where is it? Directories beginning with a
. are called hidden files and do not appear when you list the files with an
ls. To see hidden files, we have to add a modifier to our
-a which tells our terminal to list all:
$ ls -a .git
On Windows you can use
> ls -force
There it is! The .git directory is a directory like any other. Let's
cd into it and
ls it's contents.
$ cd .git $ ls HEAD description info refs config hooks objects
We aren't going to spend ANY time in this directory. The work done here to track our files is going to happen automatically. In fact, the reason the directory is hidden is to help ensure that we stay out of it to avoid making any changes to the very important work that Git will be doing for us. Now, as we add, update and delete files, Git will be in the background like a scribe, making notes of every change in our project directory.
So, let's return to the top level of our project directory by changing directories again, moving up one level:
$ cd ..
Now, we are ready to add a new file to our project. This will be the HTML page that will say "Hello" to the world.
initialize: In Git, to create a new, empty repository to track changes to the project directory. Created in the project directory.
global: A configuration option that refers to every directory in every location of the device.
hidden files: Are not listed with an
ls terminal command, but will be displayed with an
ls -a terminal command. The .git directory is hidden by default.
This workflow is only for students pair programming in person at Epicodus.
If you are working independently, such as on an independent project, you'll need to set up your git credentials so that your commits are properly attributed to you. Go to the root directory of the project you are working on to configure your user name and email:
$ git config user.name "Padma Patil" $ git config user.email [email protected]
This sets up a local git configuration for just this one project. You will need to do the same thing with any other projects you work on for the day. Don't set up a global configuration for git credentials on Epicodus computers - you might end up getting an accidental attribution for someone else's work if they forget to set up a local configuration.
$ cd Desktop $ mkdir hello-world $ cd hello-world $ git init
git init: Initializes new local Git repository.
git config --global user.name ___: Globally configures Git profile for entire device (use only when working solo).
git about: Verifies the current pair assignment.