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).

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.

Get our Free Cheat Sheet Package

About Us

As the makers of Tower, the best Git client for Mac and Windows, we help over 80,000 users in companies like Apple, Google, Amazon, Twitter, and Ebay get the most out of Git.

Just like with Tower, our mission with this platform is to help people become better professionals.

That's why we provide our guides, videos, and cheat sheets (about version control with Git and lots of other topics) for free.