Git: Working with a remote

A remote is a clone of your repository, positioned on another machine.

GitHub is one of the most commonly used remotes.

If you have an existing repository, you can publish it on GitHub.

The procedure involves creating a repository on the platform, through their web interface, then you add that repository as a remote, and you push your code there.

To add the remote type

git remote add origin

An alternative approach is creating a blank repo on GitHub and cloning it locally, in which case the remote is automatically added for you

Once you’re done, you can push your code to the remote, using the syntax git push <remote> <branch>, for example:

git push origin main

You specify origin as the remote, because you can technically have more than one remote. That is the name of the one we added previously, and it’s a convention.

The same syntax applies to pulling:

git pull origin main

tells Git to pull the main branch from origin, and merge it in the current local branch.

Lessons in this unit:

0: Introduction
1: Installing Git
2: Initialize a repository
3: Commit changes
4: Branches
5: Push and pull
6: ▶︎ Working with a remote
7: Solving conflicts
8: .gitignore
Want to learn more? Check out our courses