Establish a connection

It is common for a team to have a central repository - a single "source of truth" can be helpful for keeping a team in sync. However, insofar as git is concerned, your local repository is just as good as the team repository. There's nothing special about the team server, it works exactly the same way that the repository on your computer works. Any repository can talk to any other once it establishes a connection.

In DiffPlug, you can see which servers you can communicate with by clicking the Sync tab and then looking at the Remotes section. Each server has its own button. If you click the button, you can see the details for that server.

If you just started a new project, then this section will be empty. If you cloned the project from a central server, then there's probably one remote named "origin". A remote is just a URL with a nickname. There are three kinds of URL:

  1. file is for a repository on your local hard drive or a shared drive. You probably won't use this much, but it's great for learning about synchronizing because you can manipulate both sides of the connection.
    • file:///C:/Users/<username>/Documents/gitfromscratch (windows)
    • file:///Users/<username>/Documents/gitfromscratch (mac)
    • file:///home/<username>/Documents/gitfromscratch (linux)
  2. https is for a repository hosted on the internet. Almost every service which provides git hosting supports the HTTP / HTTPS protocol.
    • Technically, http is also an option, but it's easy to hack. Always use https!
  3. ssh/git is common if you work with lots of linux machines, but you'll probably never use it otherwise. We won't discuss it in this tutorial.
    • git:// (insecure, read-only)
    • ssh:// (secure, read/write)

You can have as many remotes as you'd like, but usually there will be just one central server named "origin". If you and Joan are working closely together, you might connect to her repository and call it "joan".

Creating a new remote

In the following sections, we're going to show how you can synchronize your commits with a remote. While you're learning, it can be helpful to make a "dummy" remote that you can tinker with. To make a dummy remote, just copy-paste your whole git repository to a new folder. This will behave just like any other remote, but you can manipulate it directly to test various situations.

To add a normal https or ssh/git remote, just click the plus.

Add a remote

Now that we can connect to another git repository, we'll look at the easiest thing to share: tags.