64

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?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Sandbox
  • 7,910
  • 11
  • 53
  • 67
  • On your local machine it means local on somewhere like github this means it is on a **remote** server. – Popeye Jan 02 '14 at 18:28
  • 2
    See perhaps this question: http://stackoverflow.com/q/13072111/26702. But to answer your question, local and remote are relative terms in this case. Local is the machine where you are. So you are cloning *from* the remote and creating a local version. – Telemachus Jan 02 '14 at 18:30
  • possible duplicate of [Git branching: master vs. origin/master vs. remotes/origin/master](http://stackoverflow.com/questions/10588291/git-branching-master-vs-origin-master-vs-remotes-origin-master) – random Jan 04 '14 at 23:57
  • 15
    **remote** = remote repository. Stuff that's on your hard drive is local. Stuff that's on GitHub's server is remote. **origin** = the default name of the remote repository on GitHub corresponding to the repo you're currently in on your machine. **master** = the default name of the initial branch of a repository. So, "origin master" is the default branch of your repository on GitHub. That's why you do `git push origin master` to update GitHub based on the changes you committed locally. – Šime Vidas Jan 05 '14 at 00:01
  • These are super basic questions about git. Why not find a good git tutorial and read it? – Matt Greer Jan 05 '14 at 00:07
  • 5
    @MattGreer super basic is very subjective. There are a lot of questions which are super basic but are still answered on SO. I have gone through couple of tutorials on git and I can use it to get my work done, but my concepts aren't clear yet and hence these questions on git. – Sandbox Jan 05 '14 at 04:18
  • @MattGreer I know this is many years later, but I am currently doing an 'Into to Git' course and found this answer because I couldn't understand the vague explanation/assumed knowledge version in the course. Well explained answers to super basic questions are extremely valuable. I am very grateful to those who take the time to answer basic questions really well. – The_Tams Oct 28 '21 at 14:01

3 Answers3

71

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 at git@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.

Community
  • 1
  • 1
Popeye
  • 11,839
  • 9
  • 58
  • 91
22

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Emil Davtyan
  • 13,808
  • 5
  • 44
  • 66
17
Q) What does remote mean? When cloning a repository located at a central location, aren't we creating its remote version?
Answer:

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 the repository is hosted for collaborators is the "remote".

Q) When I execute the command
$ git remote

I get origin. What does this mean?
Answer:

(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 repository).

Q) When I execute
$ git branch -r

I get origin/master. Now what is this?
Answer:

origin is the shortname created by Git for you to refer to your remote repository; master being the default branch pointing to the last commit Therefore, "git branch -r" will list the remote (origin) branch (master).

References:

  1. Git Basics - Working with Remotes
  2. Git Branching - Branches in a Nutshell
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
gawkface
  • 2,104
  • 2
  • 27
  • 29
  • 1
    I wish that standards, such as the Simplified Technical English standard were applied to git syntax. The git system is fundamental. The abstract and nebulous syntax make git confusing and difficult to use. – Doug Kimzey Aug 11 '21 at 13:08
  • 1
    @DougKimzey git perhaps went this way instead: https://xkcd.com/927 – gawkface Aug 16 '21 at 14:18