zell
zell

Reputation: 10204

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

Another question: some tutorial shows me this workflow

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

Upvotes: 86

Views: 141780

Answers (4)

agmin
agmin

Reputation: 9348

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!

Upvotes: 60

velocity
velocity

Reputation: 2076

The need of a remote repository instance on github for example is only to share the code with other programmers, since they can' just access your git repo (unless they connect to your pc using your ip an still then they only have access to your changes only but not the changes of other programmers), that' why commit your changes from you local repository to the remote/central repo so that other developers can check them out and finally have end up wih a same state of the software. But at the end if you are the only developer, you don't really need a remote/central repo.

Upvotes: 0

Quentin
Quentin

Reputation: 943142

If I have not yet set a remote repository, how can Git know where to commit my README file??

You are committing to your local repository (which is a proper repository with its own change control; it isn't just a local checkout … since you created it locally, it isn't even a local checkout!).

If you want to send changes to a remote repository (to back them up, make them available to other members of the team, or publish them to the world), you must push them.

Upvotes: 13

SLaks
SLaks

Reputation: 887275

Your quoted statement is correct.

You don't need to have a remote repository at all.
You can have the full git experience, with commits, branches, merges, rebases, etc, with only a local repository.

The purpose of a remote repository (eg, GitHub) is to publish your code to the world (or to some people) and allow them to read or write it.

The remote repository is only involved when you git push your local commits to a remote repository, or when you git pull someone else's commits from it.

Upvotes: 24

Related Questions