Remotes

Author

Marie-Hélène Burle

Remotes are copies of a project and its history.

They can be located anywhere, including on external drive or on the same machine as the project, although they are often on a different machine to serve as backup, or on a network (e.g. internet) to serve as a syncing hub for collaborations.

Popular online Git repository managers & hosting services:

Let’s see how to create and manage remotes.

Creating a remote on GitHub

Create a free GitHub account

If you don’t already have one, sign up for a free GitHub account.

To avoid having to type your password all the time, you should set up SSH for your account.

Create an empty repository on GitHub

  • Go to the GitHub website, login, and go to your home page.
  • Look for the Repositories tab & click the green New button.
  • Enter the name you want for your repo, without spaces.
  • Make the repository public or private.

Getting information on remotes

List remotes:

git remote

List remotes with their addresses:

git remote -v

Get more information on a remote:

git remote show <remote-name>

Example:

git remote show origin

Managing remotes

Rename a remote:

git remote rename <old-remote-name> <new-remote-name>

Delete a remote:

git remote remove <remote-name>

Change the address of a remote:

git remote set-url <remote-name> <new-url> [<old-url>]

Getting data from a remote

If you collaborate on a project, you have to get the data added by your teammates to keep your local project up to date.

To download new data from a remote, you have 2 options:

  • git fetch
  • git pull

Fetching changes

Fetching downloads the data from a remote that you don’t already have in your local version of the project:

git fetch <remote-name>

The branches on the remote are now accessible locally as <remote-name>/<branch>. You can inspect them or you can merge them into your local branches.

Example:

git fetch origin

Pulling changes

Pulling fetches the changes & merges them onto your local branches:

git pull <remote-name> <branch>

Example:

git pull origin main

If your branch is already tracking a remote branch, you can omit the arguments:

git pull

Pushing to a remote

Uploading data to the remote is called pushing:

git push <remote-name> <branch-name>

Example:

git push origin main

You can set an upstream branch to track a local branch with the -u flag:

git push -u <remote-name> <branch-name>

Example:

git push -u origin main

From now on, all you have to run when you are on main is:

git push


noshadow

by jscript