111

When I run:

git push origin master

...what is the meaning of origin in this context?

2
  • 7
    Look in The Git tutorial - "When you are working in a small closely knit group, it is not unusual to interact with the same repository over and over again. By defining remote repository shorthand, you can make it easier". If you don't do that, origin is used by default.
    – sakisk
    Mar 11, 2011 at 8:58
  • 1
    Related post - What is “origin” in Git?
    – RBT
    Feb 12, 2019 at 11:03

8 Answers 8

94

git has a concept of "remotes" - these are like easy nicknames for a repository, so you don't have to use its full URL every time you want to refer to another repository.

origin is just a remote like any other, but you see it very frequently since when you clone a repository for the first time, git clone will by default set up a remote called origin to refer to the URL that you cloned from.

If you do git remote -v that will show you all the remotes you have set up in your local repository, and the URLs that they refer to. (You'll see that it's a bit more complex than I said above, in that a remote can refer to a different URL for pushing and fetching, but you probably don't need to worry about that. :))

3
  • What about the command git remote add origin? Why would you add an origin? stackoverflow.com/a/8248542/719689
    – AlxVallejo
    Aug 21, 2012 at 13:09
  • 3
    @AlxVallejo: You might add the origin remote yourself if you'd initialized a repository yourself, rather than doing it via git clone. Sep 11, 2012 at 8:25
  • @MarkLongair what we use master at the end of the code Nov 16, 2016 at 12:28
80

origin is the default name of the remote git repository you cloned from. Have a look at .git/refs/remotes/origin/* and .git/config within your sources to see how git knows about it.

8
  • 7
    I would say "cloned your repository from" not "checked out your sources from" - the latter is a holdover phrase from centralized VCS, and can be a bit misleading to DVCS beginners.
    – Cascabel
    Mar 11, 2011 at 16:17
  • 1
    What about the command git remote add origin? Why would you add an origin? stackoverflow.com/a/8248542/719689
    – AlxVallejo
    Aug 21, 2012 at 13:06
  • 7
    git remote add origin means to add a remote repository named origin, which doesn't have any special technical meaning, it's just a widely used default name for an original remote repository. You can use foobar instead of origin if you like.
    – skuro
    Aug 25, 2012 at 0:21
  • 2
    @AlxVallejo that is often used when you did not clone from that repository, but rather you created the repository locally and created origin elsewhere as the remote repo.
    – Matt
    Apr 23, 2013 at 20:31
  • 4
    @KasunSiyambalapitiya that's the branch name. With git push origin master you tell git to push all of the commits in the currently checked out local branch (i.e. from your file system) to the remote repo identified by the name origin on its remote branch named master.
    – skuro
    Nov 16, 2016 at 13:42
41

The origin is where you got the code from origin-ally.

2
  • 3
    For me, it's not a joke but a mnemotechic rule to remember what origin means. And one I like, by the way +1
    – MiGU
    Sep 16, 2016 at 9:47
  • 1
    Whilst I enjoy your dad joke, it's not necessarily true. I can create a new repo locally and commit to it without any knowledge of a remote. I can later create a remote named origin and push to it all of the commits I've made locally. Origin doesn't have to be the original source of the repository.
    – Rob Bell
    Jan 20, 2017 at 14:16
4

This would be help

https://www.git-tower.com/learn/git/glossary/origin

n Git, "origin" is a shorthand name for the remote repository that a project was originally cloned from. More precisely, it is used instead of that original repository's URL - and thereby makes referencing much easier.

Note that origin is by no means a "magical" name, but just a standard convention. Although it makes sense to leave this convention untouched, you could perfectly rename it without losing any functionality.

In the following example, the URL parameter to the "clone" command becomes the "origin" for the cloned local repository:

git clone https://github.com/gittower/git-crash-course.git

2

origin is remote created by the git itself when you for the first clone the repo to point the URL from which you created the clone. eg: origin [email protected]:/PROJECT_U

0

"Origin" is the name of the remote repository where you want to publish your commits. By convention, the default remote repository is called "origin," but you can work with several remotes (with different names) at the same time.

0

Putting it in very simple way, let see where origin comes from. When you first clone your repo from a remote server, or cloud i.e. GitHub, you use either the HTTPS, SSH, or GitHub CLI link to do the cloning. In my example, I use the URL

git clone https://github.com/****/my-first-repo.git

to clone my project. So, the origin of my project is on GitHub, therefore the URL link below that point to my remote repo on GitHub is the origin

https://github.com/****/my-first-repo.git

Using bash CLI if I type git remote -v , I get the same URL as below

$ git remote -v
origin  https://github.com/****/my-first-repo.git (fetch)
origin  https://github.com/****/my-first-repo.git (push)

This output confirms that the origin is the URL as stated above.

Now, if you want to push your master branch (now called main) to the origin, instead of using

git push https://github.com/****/my-first-repo.git master

it's just very simple and clear to use

git push origin master

Hope this help someone understand the concept.

0

Simple terms:

git push origin master
  1. git: attention computer, the following commands are for the git library, I hope I have it installed.
  2. push: I am going to take my code, and shove it to this Github repo.
  3. origin: The default codename for the repository that keeps my code on my github page. (You know when you did git init, or git clone? It sets up a git storage unit basically, and that storage unit on github, and it has a default identifier as the 'origin'. When you push, all your code goes into this storage thing called the origin.
  4. master: on my repo called origin, grab the main branch, which is called master.

To recap: Hi machine, use github tools to take the code i'm working on, and put it online. Put it in the project this repo is part of, that was created on github (called origin), and store it in whatever branch I say, in this case 'master'.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.