Skip to main content
Title slide: Yes, You Can Git! Introduction to Git and GitHub

Learning git: Locations, Remotes, and GitHub

Where is code located? The basics of remotes for new git and GitHub users.
tech
git
learning
github
Author

Carol Willing

Published

July 1, 2019

When you are new to git and GitHub, one of the first things that is helpful to learn is where your code is located. Do you want to contribute to open source or a friend’s project?

Two concepts will help you get started:

Inspired by a talk given at Write Speak Code 2016.

Title slide: “Yes, You Can Git! Introduction to Git and GitHub,” Carol Willing, Write Speak Code, June 17, 2016

Title slide: “Yes, You Can Git! Introduction to Git and GitHub,” Carol Willing, Write Speak Code, June 17, 2016

Tool and Service

git is an open source tool which can be installed on a variety of computer systems.

GitHub is a cloud service that stores source code repositories.

Slide “Chatting with friends”: git is a tool that puts you in charge of source files; GitHub is a service for sharing and collaboration. Beside it, a poster reading “Some of my best friends are abstract.”

Slide “Chatting with friends”: git is a tool that puts you in charge of source files; GitHub is a service for sharing and collaboration. Beside it, a poster reading “Some of my best friends are abstract.”

Understanding Repository Locations

By understanding this concept, your mastery of git and GitHub for development will advance quickly.

The old saying, “Naming is hard.”, definitely applies to git. While a handy tool, the jargon around using git makes it difficult for a new user to grasp concepts.

Slide “Naming places: local (you are here), origin, upstream” over a photo of orange cosmos flowers and a butterfly beside a lake

Slide “Naming places: local (you are here), origin, upstream” over a photo of orange cosmos flowers and a butterfly beside a lake

First, let’s look at three locations: local, origin, and upstream. Code can be stored in all of these locations.

Three labeled photos: LOCAL (git) over a laptop and a handmade robot owl; ORIGIN (you on GitHub) over a river seen from the air; UPSTREAM (open source project on GitHub) over snowy mountains in clouds

Three labeled photos: LOCAL (git) over a laptop and a handmade robot owl; ORIGIN (you on GitHub) over a river seen from the air; UPSTREAM (open source project on GitHub) over snowy mountains in clouds

Let’s start with local. The local location is the git tool running on your computer system.

For consistency, we will name the repository location of your account on GitHub, origin.

Finally, we will refer to the open source project’s repository with the location, upstream.

Diagram: LOCAL (git) on the left of a dotted line; ORIGIN (you on GitHub) and UPSTREAM (open source project on GitHub) on the right, grouped as remote

Diagram: LOCAL (git) on the left of a dotted line; ORIGIN (you on GitHub) and UPSTREAM (open source project on GitHub) on the right, grouped as remote

What is a fork?

The process of creating a copy of an open source project and locating it in your GitHub account is called forking. In the GitHub user interface, you would do this by navigating to the open source project page and clicking the fork button.

Slide “Fork an open source project”: clicking Fork on the upstream repository gentlecodegarden/wsc-music creates the origin copy willingc/wsc-music on GitHub

Slide “Fork an open source project”: clicking Fork on the upstream repository gentlecodegarden/wsc-music creates the origin copy willingc/wsc-music on GitHub

Getting a project’s code onto a local system

The process of cloning makes a replica of the repository located at the specified URL: git clone <URL> where <URL> is the repository’s project page that you wish to clone.

Slide “Clone your fork of an open source project to your local computer”: terminal running git clone, git status, and git remote -v, which shows origin pointing to github.com/willingc/wsc-music

Slide “Clone your fork of an open source project to your local computer”: terminal running git clone, git status, and git remote -v, which shows origin pointing to github.com/willingc/wsc-music

Listing and adding remotes

A remote is the term that git uses to refer to any repository located in version control outside of your local computer.

git remote -v will print all of the remotes that a local repository has access to. In this example, you can see that there is only one remote, origin, which corresponds to the repository on my GitHub account.

Slide “Add a remote”: terminal running git remote add upstream with the gentlecodegarden/wsc-music URL; git remote -v then lists both origin and upstream

Slide “Add a remote”: terminal running git remote add upstream with the gentlecodegarden/wsc-music URL; git remote -v then lists both origin and upstream

To add a path from local to the upstream open source project, we need to tell git where the location of the open source project is. We can do this with the command: git remote add upstream <URL> where <URL> is the open source project’s repository that you to have a path accessible from local.

Recap

Remember:

  • git is a tool
  • GitHub is a service
  • remotes are locations of different repositories
  • local usually refers to your local computer
  • remotes, often origin and upstream, are other repositories which are located somewhere different from local

Review slide: fork an open source project, then clone your fork. LOCAL is ~/myprojects/wsc-music; the remotes are ORIGIN at github.com/your-username/wsc-music and UPSTREAM at github.com/gentlecodegarden/wsc-music

Review slide: fork an open source project, then clone your fork. LOCAL is ~/myprojects/wsc-music; the remotes are ORIGIN at github.com/your-username/wsc-music and UPSTREAM at github.com/gentlecodegarden/wsc-music

There is still lots to learn about git and GitHub workflows. I hope this gives you a foundation to build upon.

Back to top