Remotes#

We are now going to introduce the concept of a remote repository: a pointer to another copy of the repository that lives on a different location. This can be simply a different path on the file system or a server on the internet.

For this discussion, we’ll be using remotes hosted on the GitHub.com service, but you can equally use other services like BitBucket or Gitorious as well as host your own.

Let’s first take a look to see if there is a remote associated to the test repository.

git remote -v

Since the above cell didn’t produce any output after the git remote -v call, it means we have no remote repositories configured. We will now proceed to do so. Once logged into GitHub, go to the new repository page and make a repository called test. Do not check the box that says Initialize this repository with a README, since we already have an existing repository here. That option is useful when you’re starting first at GitHub and don’t have a repository made already on a local computer.

We can now follow the instructions from the next page:

git remote add origin https://github.com/fperez/test.git
git branch -M main
git push -u origin main

Let’s see the remote situation again:

git remote -v

We can now see this repository publicly on github.

Let’s see how this can be useful for backup and syncing work between two different computers. I’ll simulate a 2nd computer by working in a different directory…

cd ..
git clone https://github.com/fperez/test.git test2
cd test2
pwd
git remote -v

Let’s now make some changes in one ‘computer’ and synchronize them on the second.

cd test2  # working on computer #2

echo "More new content on my experiment" >> experiment.txt
git commit -a -m"More work, on machine #2"

Now we put this new work up on the GitHub server so it’s available from the internet

git push

Now let’s fetch that work from machine #1:

cd ..
cd test 
git pull