Remotes are repositories which serve as copies of a project and all of its history
They can be anywhere, including on an external drive or even on the same machine as the project
Often however, remotes are on a different machine to serve as backup or on a network (possibly the internet) to be accessible by several persons and serve as a syncing hub for collaborations
A number of online Git repository managers and hosting services have become popular remotes for Git projects. E.g.:
A project can have several remotes
These remotes are characterized by an address (or a path if they are local) & identified by a name of your choice
First, you need to create a new GitHub repository
Go to https://github.com , login, and go to your home page
Look for the Repositories tab, then click the green New button
Enter the name you want for your repo, without spaces
It can be the same name you have for your project on your computer (it would be sensible and make things less confusing), but it doesn’t have to be
You can make your repository public or private. Choose the private option if your research contains sensitive data or you do not want to share your project with the world. If you want to develop open source projects, of course, you want to make them public
Click on the Code green drop-down button, select SSH (if you have set SSH for your GitHub account ) or HTTPS (if you haven’t) and copy the address
Then, go back to your command line, cd inside your project if you aren’t already there and add your remote
You add a remote with:
git remote add <remote-name> <remote-address><remote-name>
is only a convenience name that will identify that remote. You can choose any name, but since Git automatically call the remote origin when you clone a repo, it is common practice to use origin as the name for the first remote
<remote-address> is the address of your remote in the https form or—if you have set SSH for your GitHub account —the SSH form
git remote add origin git@github.com:<user>/<repo>.gitgit remote add origin https://github.com/<user>/<repo>.gitIf you are working alone on this project and only wanted to have a remote for backup, you are set
If you don’t want to grant others write access to the project and only accept contributions through pull requests, you are also set
If you want to grant your collaborators write access to the project however, you need to add them to it
To list remotes, run:
git remoteTo list the remotes with their addresses, run:
git remote -vYou can see that your local project now has a remote called origin and that it has the address of your GitHub repo
To get yet more information about a particular remote, you can run:
git remote show <remote-name>git remote show originYou rename a remote with:
git remote rename <old-remote-name> <new-remote-name>You delete a remote with:
git remote remove <remote-name>You can change the url of the remote with:
git remote set-url <remote-name> <new-url> [<old-url>]If you collaborate on your project through the GitHub remote, you will have to get the data added by your teammates to keep your local project up to date
To download new data from the remote, you have 2 options:
git fetch
git pullFetching downloads the data from your 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.
git fetch originPulling does 2 things: it fetches the data (as we just saw) and it then merges the changes onto your local branches.
git pull <remote-name> <branch>git pull origin mainIf your branch is already tracking a remote branch (see below), then you simply need to run:
git pullNow, how do you upload data to the remote?
Uploading data to the remote is called pushing and is done with:
git push <remote-name> <branch-name>To push your branch main to the remote origin:
git push origin mainYou can also set an upstream branch to track a local branch with the -u flag:
git push -u origin mainFrom now on, all you have to run when you are on main is:
git pushGit knows that your local main branch is being tracked by the upstream main branch