What is "origin" in Git?

Question

When I run:

git push origin branchname

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

Answer

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

How to use Visual Studio Code as default editor for git?

Why does git say "Pull is not possible because you have unmerged files"?