Practical Git: Create local repos with git init

Trevor Miller
InstructorTrevor Miller

Share this video with your friends

Send Tweet
Published 7 years ago
Updated 4 years ago

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 this; we use GitHub for this remote repository as an example, but keep in mind that any Git repo hosting service will work.

[00:00] 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.

[00:19] 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.

[00:45] 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.

[01:06] 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.

[01:33] 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.

[01:51] 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.

[02:12] 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.

ayhan
ayhan
~ 6 years ago

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

Trevor Miller
Trevor Millerinstructor
~ 6 years ago

Thank you!

Stephen
Stephen
~ 6 years ago

I was wondering why you decided to jump directly to using remote this early in the course? Apart from there being more options to set up remote repos, (such as bitbucket for example), remote repos aren't not particularly a fundamental aspect of beginning git. I think this should be explained better in this section.

Trevor Miller
Trevor Millerinstructor
~ 6 years ago

Hey Stephen, thanks for the feedback and watching. I'll add more information to the lesson's description to explain that GitHub is just one example of many options for setting up a remote; however, I do feel that showing setting up a remote this early is valuable as the greatest benefit of Git (in my opinion) is the distributed nature of working with multiple people and multiple machines.