问题
What does remote mean? When cloning a repository located at a central location, aren't we creating its remote version?
When I execute the command
$ git remote
I get origin. What does this mean?
When I execute
$ git branch -r
I get origin/master. Now what is this?
回答1:
I found a fantastic answer here:
As you probably know, git is a distributed version control system. Most operations are done locally. To communicate with the outside world, git uses what are called remotes. These are repositories other than the one on your local disk which you can push your changes into (so that other people can see them) or pull from (so that you can get others changes). The command
git remote add origin git@github.com:peter/first_app.git
creates a new remote called origin located atgit@github.com:peter/first_app.git
. Once you do this, in your push commands, you can push to origin instead of typing out the whole URL.
I would recommend reading the whole answer.
回答2:
A remote
in git is basically a bookmark for a different repository from which you may wish to pull or push code.
The bookmarked repository may be on your local computer in a different folder, on remote server, or it may even be the repository itself ( I haven't tried this ) but the simplest analogy is a bookmark.
The repository doesn't even have to be a version of your repository, it may even be a completely unrelated repository.
回答3:
Q) What does remote mean? When cloning a repository located at a central location, aren't we creating its remote version?
Ans)
Remote repositories are versions of your project that are hosted on the Internet or network somewhere.
So, your point of reference is the machine on which you are running your commands (your laptop) and ergo the central location where repo is hosted for collaborators is the "remote"
Q) When I execute the command
$ git remote
I get origin. What does this mean?
Ans)
(git remote command) lists the shortnames of each remote handle you’ve specified. If you’ve cloned your repository, you should at least see origin – that is the default name Git gives to the server you cloned from.
Specifying git remote -v will give you the shortname and corresponding url of the "remote" (aka the repo)
Q) When I execute
$ git branch -r
I get origin/master. Now what is this?
Ans)
origin being the shortname created by git for you to refer to your remote repo; master being the default branch pointing to the last commit
Therefore, "git branch -r" will list the remote(origin) branch(master)
References:
- https://git-scm.com/book/en/v2/Git-Basics-Working-with-Remotes
- https://git-scm.com/book/en/v2/Git-Branching-Branches-in-a-Nutshell#_git_branching
来源:https://stackoverflow.com/questions/20889346/what-does-git-remote-mean