What is "origin" in Git?
When I run:
git push origin branchname
What exactly is origin
and why do I have to type it before the branch name?
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
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.
Git has the concept of "remotes", which are simply URLs to other copies of your repository. When you clone another repository, Git automatically creates a remote named "origin" and points to it.
You can see more information about the remote by typing git remote show origin
.
origin
is the default alias to the URL of your remote repository.
Simple! "origin" is just what you nicknamed your remote repository when you ran a command like this:
git remote add origin [email protected]:USERNAME/REPOSITORY-NAME.git
From then on Git knows that "origin" points to that specific repository (in this case a GitHub repository). You could have named it "github" or "repo" or whatever you wanted.