Search code examples
gitgithubgit-remote

What does it mean for a git repo to have multiple remotes?


I was reading over Pro Git, and the section on remote repositories is sort of confusing for me. In particular, there's a section where the author says:

http://git-scm.com/book/en/Git-Basics-Working-with-Remotes

"If you have more than one remote, the command lists them all. For example, my Grit repository looks something like this.

$ cd grit
$ git remote -v
bakkdoor  git://github.com/bakkdoor/grit.git
cho45     git://github.com/cho45/grit.git
defunkt   git://github.com/defunkt/grit.git
koke      git://github.com/koke/grit.git
origin    [email protected]:mojombo/grit.git

This means I can pull contributions from any of these users pretty easily. But notice that only the origin remote is an SSH URL, so it’s the only one I can push to (we’ll cover why this is in Chapter 4)."

My question is, what are the four remote repositories (bakkdoor, cho, defunkt, koke) in relation to grit? Are they repos make up the grit repo? Or are they separate copies of the same grit repo? Or are they not related at all?

Furthermore, if the grit repo is made up of those 4 separate repos, why are they separately named? Wouldn't it make more sense to have them all under "origin"?

As you can see, I'm pretty much totally lost on this. I feel like the way it's being explained to me is going right over my head.


Solution

  • The idea is that you can create a remote repository ("origin") and push your project's code there. Let's say that since you are the creator of that project, your repository is considered the official version of your project.

    Suppose that you are the only one allowed to push to that remote repository, but others can pull from it.

    So other people can clone your repository and create their own remote repositories based on it (Got example, GitHub allows you to create a remote repository based on another user's repository). They can add features to your code on their own repositories. Now if they want to contribute to the official version (maintained by you), they can tell you about the new features they added and ask you to add them to your project.

    One of the ways for you to do that is to add their repositories as additional remote repositories (bakkdoor, cho45, etc... are such repositories and they are named after the GitHub users who created them). Since you don't own those repositories, you'll only have read access to them. Then you can pull whatever changes you want from them, and push them to your remote repository, thus integrating these changes into the official version.

    This type of collaboration is discussed later in the Pro Git book. You should continue reading and everything will become clearer.