Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set your subtitle preferences in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please see our video player troubleshooting guide to resolve the issue.

Remote Git Repositories and GitHub

In this lesson, you will learn what GitHub is and how to use it with git. You’ll learn about powerful GitHub features such as:

  • Issue tracking
  • Centralized cloud hosted repositories
  • Access control and account management features
  • Advanced workflow management
  • Code review features

The lesson also covers how to use common git commands and GitHub features to setup and clone repositories, add and make changes to files and, push changes up to GitHub.

00:00 Remote Repositories and GitHub. A remote repository is a common repository to which all members of a team share their changes. So, where does GitHub come into all this? Many teams use GitHub as that common central repository from which everyone must pull, or as a highly available repository. So, a little more about GitHub.

00:24 GitHub is based on and integrates tightly with Git, but it adds its own features and functionality on top of it. Some of the major benefits of using GitHub are an easily-accessed, centralized, cloud-hosted repository so you don’t have a single point of failure.

00:42 You get access control and account management features. You get an advanced workflow management capability with issue tracking and code review, to name a few things. The point is, you will still use Git and the full repository is still contained in your local working directory.

01:01 GitHub is just that remote repository cherry on top. Speaking of which, you should just go ahead and create a GitHub account right now. One, so you can follow along with the rest of these examples you’re about to run through. And two, it’s a perfect time to start getting acclimated to GitHub.

01:17 You’ll probably use it a lot. GitHub is also a surprisingly awesome place for education. There’s articles and guides all over GitHub and it’s a great place to browse and see other people’s code in the wild. Yeah!

01:30 So if you’re able to now, it’s a great time to pause and make yourself a GitHub account. It only takes a few minutes. When you come back, we’ll hop into Git and GitHub and work with local and remote repositories.

01:45 Let’s quickly cover four commands you’re going to use a lot when working with remote repositories. You will use clone to copy a repository to your local desktop.

01:57 You’ll use fetch to go fetch other people’s work from the remote repository. You’ll use pull to go fetch and then merge other people’s work into your local repository.

02:10 And finally, you’ll use push to push your changes up to the remote. And now it is time to work with GitHub, so let’s hop back into the console and go ahead and pull up GitHub in a browser. Okay. Let’s start working with GitHub a little bit here.

02:28 We’re going to create a remote repository in GitHub. So when you first log in, you’re going to have somewhere that says Repositories, and you’re going to want to find New and click it.

02:41 Make it Public or Private—it’s up to you. Go ahead and name it. We’ll stick with the Zen theme.

02:49 And generally, you always want to initialize with a README, just best practice. And something cool about GitHub is you can automatically add a .gitignore file for whichever language you’re using. So if you go to look up Python here, it’ll automatically toss a .gitignore with common files that you’d want to ignore when working on a Python project. Pretty handy.

03:13 So, let’s go ahead and create it.

03:17 Now we have a remote repository set up on GitHub. If you come over here to the Clone or download button, you can grab what’s called the URI for the repository, and then we can tell Git to clone it to our local desktop. So let’s try that.

03:34 Go ahead and copy this URI and switch back to your terminal. And we want to make a new repository for it, so I’m going to back up one directory and just make a directory for remote_repo.

03:52 And then cd into it.

03:57 You can see right now, if I list it, that it’s empty. And now we’re going to clone our remote with git clone and then paste that URI in there.

04:13 So, what happened? Let’s check it out! We’ve got a new directory called zen_remote, which is a Git repository. And if I list it, the only thing in it right now is the README.

04:28 So, now that we have a local copy of the remote, what happens when people—say, other people working on the project—make updates to that remote repository? They’re typically not going to come down automatically, so let’s simulate that. Let’s hop back into GitHub and just click this Create new file button here. This will just create a text file for us.

04:56 Let’s do something like that

05:01 and then commit our new file. So now I’ve got this hello_from_remote file in our remote repo. And if we hop back into our local here, it’s not there. This is when we do a git pull.

05:19 And let’s see if it came down. Sure did! And if I list it here, let’s take a look, cat hello_from_remote. There it is! But what happens if we make a change to that file in our local?

05:33 So if we vim into that file, hello_from_remote, let’s add a line.

05:46 Escape, Shift plus colon (:), wq, Enter. And now if we cat that file, we’ve got a change here on local. So we’ve got to commit it first

06:01 because it’s modified. So we do git commit, our commit message.

06:11 Oops, forgot to add it.

06:16 So let’s stage it and now commit it. I’m just going to hit Up arrow twice. There we go. So even though we committed it to our local, we still need to push it up to the remote now.

06:31 So, you guessed it. We’re going to run git push.

06:41 And there we go! So, let’s hop over to GitHub and see if the change came through. Let’s do a refresh here. We can see our commit message updated there. And if I click on a file, we got our Hello back from local! There you go!

06:59 You worked with a remote repo.

Become a Member to join the conversation.