Connecting a Remote Repository
When you clone a repository from a remote server, Git automatically remembers this connection for you. It saves it as a remote called "origin" by default.
In other cases where you started with a fresh local repository, no remote connections are saved. In that situation, we need to connect our local repository to a new remote before we can try some remote interactions:
$ git remote add crash-course-remote
https://github.com/gittower/git-crash-course-remote.git
Let's check if this worked out ok:
$ git remote -v
crash-course-remote https://github.com/gittower/git-crash-course-remote.git (fetch)
crash-course-remote https://github.com/gittower/git-crash-course-remote.git (push)
origin https://github.com/gittower/git-crash-course (fetch)
origin https://github.com/gittower/git-crash-course (push)
Note that each remote repository consists of two lines: the first one is the "fetch URL" which is used for reading access. The second one is the "push URL", used when you want to write data to the remote. In many cases, both URLs are the same. However, you can also use this to define different URLs for read and write access (for security and performance reasons).
Tip
Adding Remotes in Tower
In case you are using the Tower Git client, you can add a remote repository easily, right from the sidebar:
Also note that you can connect as many remotes to a local repository as you like. In my case, you saw that another remote named "origin" is already present - although we didn't configure this! This was added by Git automatically when we cloned from the remote server (which we did at the beginning of this book). Exactly as with the "master" branch, the name "origin" for this remote is only a naming convention. It's just a normal remote repository like any other.