Bummer! This is just a preview. You need to be signed in with a Basic account to view the entire video.
Initializing a Repository4:13 with Jay McGavren
Learn what "git init" does and how it works.
Our project for this course will be a simplified version of a web site for a company that makes gold, silver, and bronze medals to award at sporting events. If you launch a Treehouse Workspace using the button on this video's page, you'll see a
medals directory (directory is a fancy word for folder) with two files in it:
<!DOCTYPE html> <html> <body> <p>We have a fine selection of medals.</p> </body> </html>
<h1>Check out our bronze medals!</h1> <p>Medallion: $20</p> <p>Ribbon: $10</p>
You don't need to worry too much about the particular content of these files; if you really want to know more about HTML, visit our Introduction to HTML and CSS course.
You can create a repository within a project directory on your computer. That's what we'll do here.
We need to change into our project directory so we can turn it into a Git repo. If we type
ls and press Enter, it will run the
ls command. This lists files and directories within the current directory. By the way, the
ls command isn't part of Git, but it's a standard command on all Unix-like systems. It's worth your time to learn how to use it. We have more coverage of the
ls command in this video from our Console Foundations course.
- We can see our project directory,
medals, in the output of ls.
- To get into the
cdcommand is another important command that works on Linux, Mac and Windows systems.
cdis also covered in our Console Foundations course; you can learn more about it in this video.
- Now that we're in the project directory, we need to initialize the new repository. We'll do this with the
- Like all the Git commands we'll be using in this course, it starts with the name of the
gitexecutable, followed by a space. Then, we type the name of the subcommand we want to run, like
commitor, in this case,
- Press Enter to run it. Git will initialize a repository in the current directory, by creating a new directory named
- You won't see the
.gitdirectory at first. But
lshas a special command line option that will cause it to show all files, even hidden ones.
- If we hit Enter to run it, we can see the
.gitdirectory in the output of
Our project for this course will be a simplified version of a website for
a company that makes gold, silver, and bronze medals to award at sporting events.
If you launch a Treehouse workspace using the button on this videos page, you'll see
a medals directory, directory's a fancy world for folder, with two files in it.
A medals.html file that holds the main page content, and
a bronze.html file that holds information on the store's bronze medals.
You don't need to worry too much about the particular content of these files.
If you really want to know more about html, you can see the teacher's notes for
The important part is the get commands we'll be using to track their contents.
Because we'll be making many of our changes using the console,
the sidebar may not display what the directory actually holds all the time.
You can right-click on the sidebar and choose to refresh the list, but
I don't want to do that over and over.
So I'm going to the View menu and choose Hide Sidebar.
When I need the sidebar later, I'll use the Show Sidebar menu to reveal it again.
For the most part, I'll be using simple commands that let us look at
the contents of the directory from the console.
There's two ways to get a git repository onto your computer.
One is to clone, or copy, a repo from another machine.
We'll look at this later in the course.
The other is to create a repository within a project directory on your computer.
That's what we'll do here.
Right now we're in the workspace directory which holds all of the files for
We need to change into our project directory so
we can turn it into a Git repo.
So I'll click down in the console to activate it.
And now if we type ls and press Enter, it will run the ls command.
This lists files and directories within the current directory.
By the way, the ls command isn't part of get, but it's a standard command on all
Unix-like systems, such as Mac, Linux, and the subsystem for Linux on Windows.
It's worth your time to learn how to use it.
We'll have more info in the teacher's notes.
We can see our project directory, medals, in the output of ls.
To get into the medals directory, we'll use the cd or change directory command.
Then we tap a space,
followed by the name of the directory we want to change into, medals.
We can see that the directory name in our shell prompts has changed to
And if we run again, we will see the files for our project.
Now that we are in the project directory, we need to initialize the new repository.
We will do this with the git init command.
Like all the git commands we'll be using in this course,
it starts with the name of the git executable followed by a space.
Then we type the name of the sub command we want to run like add or commit.
Or in this case, init.
That's the whole command, so press Enter to run it.
It will initialize a repository in the current directory
by creating a new directory named doc git within it.
Or at least it's supposed to.
But if we run ls again, we don't see a .git directory.
This is because the file name begins with a dot.
On Unix-like systems,
such as Linux, a dot at the start of a filename means that the file is hidden.
Let's show the sidebar and refresh it.
That Git directory won't appear there either.
But ls has a special command line option that will cause it to show all files,
even hidden ones.
Options to other commands work just like the options for the git executable.
We type ls, a space, and then the option we want, -a.
The -a stands for all, as in list all files.
If we hit Enter to run it, we can see the .git directory in the output of ls.
But why would git create this directory only to hide it from us?
The reason is that you generally don't want to directly interact with the .git
It stores all of your repository's history in a special format
that only the git command really knows how to update safely.
You do not want to modify the files in the .git directory yourself.
You could corrupt your repository's history,
meaning you would lose everything that hadn't been cloned to other computers.
Don't worry, that isn't a common problem.
It's rare for people to modify the contents of .git directly,
either accidentally or on purpose.
It just explains why the directory is hidden.
But it's much safer to modify the .git directory
indirectly by making commits through the git command.
We'll do just that in the next video.
You need to sign up for Treehouse in order to download course files.Sign up