What is origin in Git? (Or Why does it sometimes seem there are two names to refer to a remote repository?)

Anna Skoulikari
Tech Journey with Anna
4 min readAug 26, 2020

Origin is the shortname that acts like an alias for the url of the remote repository.

Let me explain with an example.

Suppose you have a remote repository called amazing-project and then you clone that remote repository to your local machine so that you have a local repository. Then you would have something like what you can see in the diagram below:

Because you cloned the repository. The remote repository and the local repository are linked.

If you run the command git remote -v it will list all the remote repositories that are linked to your local repository. There you will see that in order to push or fetch code from your remote repository you will use the shortname 'origin'.

Now, this may be a bit confusing because in GitHub (or the remote server) the project is called ‘amazing-project’. So why does it seem like there are two names for the remote repository?

Well one of the names that we have for our repository is the name it has on GitHub or a remote server somewhere. This can be kind of thought like a project name. And in our case that is ‘amazing-project’.

The other name that we have for our repository is the shortname that it has in our local repository that is related to the URL of the repository. It is the shortname we are going to use whenever we want to push or fetch code from that remote repository. And this shortname kind of acts like an alias for the url, it’s a way for us to avoid having to use that entire long url in order to push or fetch code. And in our example above it is called origin.

So, what is origin?

Basically origin is the default shortname that Git uses for a remote repository when you clone that remote repository. So it’s just the default.

In many cases you will have links to multiple remote repositories in your local repository and each of those will have a different shortname.

So final question, why don’t we just use the same name?

I will answer that question with another example. Suppose we have a friend who forks our remote repository so they can help us on our project. In the diagram below we can see that now there are two remote repositories.

And let’s assume we want to be able to fetch code from their remote repository. We can use the command git remote add <shortname> <url> in order to add a link to their remote repository in our local repository.

In the above image we can see that I used the shortname friend to refer to my friend's remote repository. So now our local repository is linked to two remote repositories:

We can also see that both of the remote repositories have the same project name amazing-project and that gives us one reason why the remote repository names in the remote server and the shortnames in our local repositories should not be the same!

Because we need a different name to refer to each remote repository we want to interact with.

If you want to go over the concept above in video form 📹 I explain all of the above in the video below:

If you like the way that I explain Git concepts feel free to check out my online course on Udemy in which I teach Git version control. 😊

You can also :

--

--

Anna Skoulikari
Tech Journey with Anna

Anna Skoulikari teaches Git and recently published a book with O'Reilly titled: Learning Git - A Hands-On and Visual Guide to the Basics of Git