Enter Your Email Address to Watch This Lesson

Your link to unlock this lesson will be sent to this email address.

Unlock this lesson and all 829 of the free egghead.io lessons, plus get Tools content delivered directly to your inbox!



Existing egghead members will not see this. Sign in.

Just one more step!

Check your inbox for an email from us and click link to unlock your lesson.



Practical Git: Create local repos with git init

2:34 Tools lesson by

Getting started with Git requires you to add a .git folder to your project on your machine and then set up that folder to point to a remote repository. In this lesson, we walk through using git init and git remote to do just that.

Get the Code Now
click to level up

egghead.io comment guidelines

Avatar
egghead.io

Getting started with Git requires you to add a .git folder to your project on your machine and then set up that folder to point to a remote repository. In this lesson, we walk through using git init and git remote to do just that.

Avatar
ayhan

great job! Good instructions. I couldn't find place to put feedback for whole course. Really well done sir

Here, we're inside of a folder called Utility Functions. If we take a look at what's inside, we have a couple of files. We want to make this folder into a Git repo. The first thing we need to do is to run git init. This will initialize an empty Git repository, as it says here.

If we output what's in this directory, we can see that there is a new .git folder at the root. If we take a look at this .git repo, we can see that there's a lot of folders and files in here. Although we're not going to get into the details of this in this lesson, the important thing to know is that all of the Git settings and information is located in this .git repo at the root of our project.

Since all of our Git information is in this .git folder, if we ever want to remove Git from our project, all we have to do is delete that folder from our project. If we were to remove .git, and take a look at our project again, we can see that Git is no longer a part of our project, including all of the information that it's gathered about our project.

If we try to run a Git command, like git add for example, it says that this is not a Git repository. Once we run git init, then we can run the command, and it no longer throws an error. Now that we have a Git repo set up locally, it won't be much use to us unless we can sync it with a repo on the Internet somewhere. That could be on GitHub, or Bitbucket, or any number of Git repo hosting services.

In my case, I'm going to use GitHub. What I've done here is, I've logged into my GitHub account. I will go to the new repository button. It's asking for our repository name. I usually use the folder name of my project. In this case, it's Utility Functions.

I will copy that and paste it here in the repo name. We'll give it a description. We can go down and say Create Repository. This takes us to a new repo page, which gives us a URL that has a .git extension. We're going to copy that URL because this is the location of our remote repo.

Back in our command line, we're going to say Git Remote Add, and then the name of our remote, which will be Origin. We'll paste in the URL that we copied. If we run that, we now have a remote set up on a repo. To verify that it was added correctly, we can type git remote.v. We can see that the URLs were added correctly.

HEY, QUICK QUESTION!
Joel's Head
Why are we asking?