HOLIDAY SALE! Save 50% on Membership with code HOLIDAY50. Save 15% on Mentorship with code HOLIDAY15.

13) Version Control Lesson

Introduction: Add GitHub Remote

8 min to complete · By Martin Breuss

In this lesson, you'll learn how to connect your local Git folder to GitHub.

Colorful illustration of a light bulb

Info: The information about Git and GitHub is stripped down to the basics you need to get started. If you want to dive deeper into using Git and GitHub for version control, check out the dedicated Version Control with Git and GitHub course.

What is GitHub

You just learned about Git, but what's the deal with GitHub? You can think of GitHub as a cloud storage for your Git repositories. It allows you to keep your code and its history safe from deletion should your computer fail, as well as allows you to access it from any machine.

Most of all, however, GitHub allows software developers to remotely collaborate on complex coding projects and give feedback to each other.

Create GitHub Account

If you have not already created an account on GitHub, please create a free GitHub account now.

Once you're logged into GitHub, click on the + icon in the top right corner of the screen and select New Repository.

You will see a screen where you need to adapt a few settings. Look at these settings one by one:

  • Name: Give the new repository a name. Call this project python-labs.
  • Description: You can leave the description blank for now.
  • Repository Type: Leave the repository type set to the default public.
  • Initialize...: Lastly, you can leave Initialize this repository with a README unchecked.

Click on Create Repository. You will see a page that looks similar to the one shown below:

New repository created page on GitHub

This means that you successfully created a GitHub repository and are ready to connect it with your local Git repository.

Steps to Add GitHub Remote

Next, you need to connect your local Git repo to your new GitHub repository. Connecting your local repository to a remote repository is called "adding a remote repository" to your local Git repository. Doing this allows you to push your code to an online repository where you can share your work and collaborate with others.

You'll need to take the following steps:

  1. Check current working directory
  2. View remotes
  3. Add your remote
  4. View remotes again

Follow the step-by-step instructions below to go over this whole process.

1. Check Current Working Directory

Make sure you're in the right directory. The right directory is the one that contains the README.md file and all the individual labs folders. If you followed along in the previous sections this will be the ~/Documents/codingnomads/labs directory. If you are not there yet, use your terminal to move there:

cd ~/Documents/codingnomads/labs

2. View Remotes

Check to see what remotes are already connected to your local repo:

git remote -v

If you have downloaded the labs folder as previously described, there shouldn't be any remotes showing up.

Colorful illustration of a light bulb

Info: If you have cloned the repository instead of downloading the ZIP file, then the original CodingNomads GitHub repository will show up as a remote. This is no problem. You can choose to keep the connection and add a second remote pointing to your own GitHub or replace the CodingNomads' one with yours. Check out the Intro to Git & GitHub course if you need help.

3. Add GitHub Remote

Now it's time to add your new GitHub repo as a remote to your local Git repository. The default name for Git remotes is origin. Add your GitHub remote under that name:

git remote add origin https://github.com/<YOUR GITHUB USERNAME>/python-labs.git

Be sure to replace <YOUR GITHUB USERNAME> with your GitHub username as shown in the image below under the section labeled, "...or push an existing repository from the command line":

New repository created page on GitHub, showing the lower part

4. View Remotes Again

Check a second time to see what remotes you have connected to your local repo now:

git remote -v

At this point, you should see that you have one remote repository called origin that points to your GitHub repository titled python-labs.

Colorful illustration of a light bulb

Note: The -v option stands for "verbose". Adding -v to the command will print out the URL that the remote is connected to. Without the -v it will only print out the names of the connected remotes, which in your case is origin

Nice work! If you get this output, then you successfully connected your local Git repository to your remote GitHub repository.

In a future lesson, you'll push your code to the GitHub cloud, both keep it safe from getting lost on your computer, and open it up for collaboration with others.

Summary: Introduction to Add Github Remote

  • GitHub is a cloud storage for your projects that your peers can access
  • GitHub protects your projects by not only storing them on your local computer, which can break

Steps to Add GitHub Remote

  1. Check current working directory
  2. View remotes
  3. Add your remote
  4. View remotes again