Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is "origin" in Git?

Tags:

git

When I run:

git push origin branchname 

What exactly is origin and why do I have to type it before the branch name?

like image 394
enchance Avatar asked Mar 02 '12 07:03

enchance


People also ask

What is Origin and Main in git?

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.

What is origin in git pull?

git pull origin/master will pull changes from the locally stored branch origin/master and merge that to the local checked-out branch. The origin/master branch is essentially a "cached copy" of what was last pulled from origin , which is why it's called a remote branch in git parlance.

What is git origin vs Remote?

A remote is just a word: a name to use to identify some other Git repository somewhere. The string origin is the default name of the (singular) remote that git clone puts in automatically, when you clone from some other ("origin"-al) Git repository. You can choose some other name, and/or add more remotes.

What is origin and branch name in git?

Just like the branch name “master” does not have any special meaning in Git, neither does “origin”. While “master” is the default name for a starting branch when you run git init which is the only reason it's widely used, “origin” is the default name for a remote when you run git clone .


2 Answers

origin is an alias on your system for a particular remote repository. It's not actually a property of that repository.

By doing

git push origin branchname 

you're saying to push to the origin repository. There's no requirement to name the remote repository origin: in fact the same repository could have a different alias for another developer.

Remotes are simply an alias that store the URL of repositories. You can see what URL belongs to each remote by using

git remote -v 

In the push command, you can use remotes or you can simply use a URL directly. An example that uses the URL:

git push [email protected]:git/git.git master 
like image 107
doelleri Avatar answered Oct 09 '22 18:10

doelleri


origin is not the remote repository name. It is rather a local alias set as a key in place of the remote repository URL.

It avoids the user having to type the whole remote URL when prompting a push.

This name is set by default and for convention by Git when cloning from a remote for the first time.

This alias name is not hard coded and could be changed using following command prompt:

git remote rename origin mynewalias 

Take a look at http://git-scm.com/docs/git-remote for further clarifications.

like image 33
Antoine Meltzheim Avatar answered Oct 09 '22 16:10

Antoine Meltzheim