Linking a Repository to GitHub

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

In Git, the command for working with remote repositories is git remote. A local repository can have multiple remote repositories. For example, you may have a link from your local repository to the copy on GitHub. At the same time, you may also have a link from your local repository to a testing server or even a friend’s repository on a shared server. You assign a nickname to each of the remotes and then can get changes from any of them and send your changes to any or all of them.

By convention, the main repository that a local repository is linked to is called origin. But you can call a remote by any nickname you want. To add a remote, you need the URL for the repository. When you’re on the main page of a repository in GitHub, the URL in the browser is correct, or you can click the <> Code button.

Two places to find the URL of a remote repository when browsing it on github.com.
Two places to find the URL of a remote repository when browsing it on github.com.

Downloading a Remote to Your Computer

The command to create a new repository on your local computer linked to a remote is git clone. If you’ve followed along and created a private repository, wait to type any of these commands; they won’t work yet. If you’ve followed along and created a public repository, use this command:

git clone <url_of_the_repository>
git clone <url_of_the_repository> <local_name>

Extra Steps for Private Repositories

When working with private repositories, you must authenticate when you git clone. However, although Git asks you for your GitHub username, it doesn’t want your GitHub password when it asks for password; it wants your Personal Access Token.

Personal Access Tokens

As you might have seen, you can do much more than look at a repository while on the GitHub website. You can also:

The Settings option in the profile menu. You may have to scroll down to find it, it's almost at the end of the list.
Csu Tiwxexst irvoam iz vqu crovoma wofo. Xei gop woqe hu bgcezq wutp mo qojp aj, uq'n uvwulz ec fma icp ec mbo luqx.

The Contents Menu permissions are the only one you need to grant for simple push and pull to the local repository.
Txi Tisveqjc Towa repkuyveegj ani nsi udbn ira fii buus ji rdukv qos mihxsa gapk owm boxf fe mpa nocin vamaxolalc.

Conflicts with an Existing Repository

If you already have a Git repository on your computer and want to link it to a GitHub remote, it’s important that you leave the options for README, .gitignore and LICENSE blank so the remote is completely empty.

Sending Your Repository to the Remote

In the local Git repository, you add the remote by typing this command:

git remote add origin <the_url_of_the_repository>
git remote -v
git push -u origin main
git push origin <this_branch> <that_branch>
git push --all

Copying Changes to Your Local

Now that you’ve gotten the local and the remote linked and can push your changes, you can learn how to bring changes to your local. The git clone command was to copy an entire repository and initialize a new one on your computer. For an existing, linked repository, get the new changes from the remote using:

git pull
git fetch
See forum comments
Download course materials from Github
Previous: New Repository Demo Next: Push & Pull Demo