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 Introduction to the Terminal 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 Introduction to the Terminal 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
You need to sign up for Treehouse in order to download course files.Sign up