Git's local repository and remote repository -- confusing concepts

zell picture zell · Oct 25, 2012 · Viewed 88.3k times · Source

If I understand correctly, Git has two sorts of repositories: one called local, another called remote. My questions are extremely naive ones about the two types of repositories.

Is that correct to say

  • Git local repository is the one on which we will make local changes, typically this local repository is on our computer.

  • Git remote repository is the one of the server, typically a machine situated at 42 miles away.

Another question: some tutorial shows me this workflow

  • mkdir myproject
  • cd myproject
  • git init
  • touch README
  • git add README
  • git commit -a -m "

I see that git init creates myproject a local repository. What I don't understand is the git commit command. If I have not yet set a remote repository, how can Git know where to commit my README file??

I hope I was clear.

[EDIT] The way I am using Git might be different from others: I use a private Git repository to backup my codes. So I think I do need a remote repository. The local repository should be nonsense in this case. Am I right? Thanks for your clarification. These are the most naive questions that I cannot find replies anywhere else...

Answer

Bishoy Hanna picture Bishoy Hanna · Aug 13, 2015

As I'm experiencing exactly the same questions like yours (coming from VSS and TFS mindset) and during the last 3 days started to understand. I would believe that these kind of diagrams would be more helpful to understand the whole picture for anyone else trapped there.

from: https://greenido.files.wordpress.com/2013/07/git-local-remote.png?w=696&h=570

Git Flow diagram 1

Another one, from: https://wiki.lsr.ei.tum.de/lib/exe/fetch.php?media=nst/programming/git_flow.jpg&w=500&tok=e87798

Git flow diagram 2