In git lingo, are origin
and remote
the same thing? Or does origin
refer to the local directory?
In the case of git push -u origin master
: Which of the following interpretation is correct?
Appreciate any clarification!
The answers to my question clarified two issues for me:
origin
refers to the remote repo, rather than the local cloned copy of the remote repo. This is not clear when one reads that origin
is an alias of remote
and is created at the time of git clone
origin
refers to the remote repo in git push -u origin master
because local copies of the repo are implied and "rarely referenced".They are two completely different things. git remote is used to refer to a remote repository or your central repository. git clone is used to copy or clone a different repository.
"origin" is the name of the remote repository where you want to publish you commits. By convention, the default remote repository is called "origin", but you can work with several remotes (with different names) as the same time. More information here (for example): gitref.org/remotes.
The origin RemoteWhen you clone a repository with git clone , it automatically creates a remote connection called origin pointing back to the cloned repository. This is useful for developers creating a local copy of a central repository, since it provides an easy way to pull upstream changes or publish local commits.
The term "git origin master" is used in the context of a remote repository. It is used to deal with the remote repository. The term origin comes from where repository original situated and master stands for the main branch. Let's understand both of these terms in detail.
In git lingo origin
is just the default name for a remote from which a repo was originally cloned. It might equally have been called source
or remote1
or just remote
.
Remember that git
is a peer-to-peer, distributed system, not one with any built-in notion of client/server, master/slave, parent/child relationships (though these might be imposed upon it by a user in a particular scenario).
All remotes are equal. origin
is simply (and literally) the first among those equals (for a cloned repo). :)
And as Jan points out in the comments, the name associated with each remote is intended for your convenience. If you find that origin
does not really work for you then you can change it.
As for your interpretations of the push
statement, your first is the closest to being correct but the push command as written will push the local master
branch to the master
branch on the remote identified by the (locally configured) name origin
.
If there is no master
branch in the remote then one will be created.
Full details of the push command and the flags, options etc are of course in the docs.
You rarely (if ever) refer to the 'local' repo explicitly since your operations are performed in the context of a repo.
No, they don't mean the same thing.
remote
, in git
-speak, refers to any remote repository, such as your GitHub or another git
server.
origin
is the, by convention, default remote name in git
. When you do a git clone <url>
, <url>
is automatically added to your local repo under the name origin
. You can, of course, add other remotes under different names using git remote add
.
When you do git push -u origin master
, what it means is "push everything from my local master to the remote named origin
". The structure of this command is, of course, more general - the more general form is git push -u <remote> <branch>
, which will push the branch named branch
to the designated remote, creating it at the far end if the remote doesn't already have it (that's what the -u
flag does).
As a further addendum, git push
, by default, will push the current branch to origin
, corresponding to git push origin <current-branch>
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With