Search code examples
gitrepository

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


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


Solution

  • Git is a distributed version control system and it makes Git awesome. Your local repository has exactly the same features and functionality as any other Git repository. So a Git repo on a server is the same as a Git repo on GitHub (granted GitHub adds additional features, but at its core, you're dealing with Git repositories) which is the same as your coworker's local repo.

    So why is that awesome? Because there is no central repo you have to have access to do your work. You can commit, branch, and party on your own repo on your local machine even without internet access. Then, when you have a connection again, you can push your changes to any other Git repo you have access to. So while most people treat a particular repo as the central repo (repository), that's a process choice, not a Git requirement.

    The point of all that was to state (as others have) that you're committing your README to your local repo. Then, whenever you choose, you can push changes from your local repo to any other repo. It's pretty nifty!