Home » Git » What is git ORIGIN & the git remote add command?

What is git ORIGIN & the git remote add command?

Git really does include some strange names, commands and terminology, and certain words crop up regularly whose meaning is not obvious. In this post I’ll explain as clearly as possible what ORIGIN is in Git. I’ll also explain some related commands such as git remote add origin. Once you’ve created your local repo and done a bit of coding you will probably want to share your code with other team members. At that point you need to push your code to a remote repo, which you need to create. So I’ll also explain how to do that to get you started.


What is a remote repository anyway?

A remote repository (or repo, for short) is an online store for your local code, an online, cloud based version of your code. Once you push your files from your local repo to your remote repo it means there is a copy of them in a remote location. So if you change your local files, the remote ones won’t change until you ‘commit’ your local changes and ‘push’ them to the remote repo. You need to set up an account with github / gitlab / bitbucket which are some of the many hosts of remote repositories.

Create the remote repo in github

Before you can do anything else you need to make sure the remote url exists in your github account, and for that to be the case you need to create a new repository. Here is a screenshot of what it looks like when you create a new repo in github.

Create new repo in github

Once created, the repository has a unique url – the url of this remote repository that I’ve created is:

https://github.com/EmilyChristy/react-bootstrap-cards

One repository can have multiple ‘remotes’ – although most generally you will only have one. However it’s good to know how to add and remove remotes. Git is case sensitive so it is fairly easy to accidentally create multiple remotes.


So what is ORIGIN in git?

ORIGIN is just a shorthand name for the url of a remote repository.

When you initially clone a repository using git clone, it automatically creates a remote connection called ORIGIN pointing back to the cloned repository.

If you haven’t deliberately changed anything about the remote – or if you have no idea what that even means, then you can presume that you have one remote, and that it’s called ORIGIN.

ORIGIN is presumed

When you start out using git it can feel as if the only time you see mention of ORIGIN is when you see an error. It’s important to understand that in many git commands certain details are presumed. In many cases you don’t have to specify ORIGIN because it’s presumed that it’s the name of your remote. In that case, all of these commands do exactly the same thing :

git fetch ORIGIN
git fetch https://remote.repo.url
git fetch

So when you type :

git fetch

… the ORIGIN part is presumed. If you had renamed your remote to MYREMOTE then you would have to type:

git fetch MYREMOTE

Set the remote repository using git remote add

There are 2 arguments to the git remote add command:

  • A remote name, for example, ORIGIN
  • A remote URL, for example, https://github.com/user/repo.git

So to set the ORIGIN in git, the full command would be:

git remote add ORIGIN https://github.com/user/repo.git

This connects the local repo to a remote repo at the address you specified. Once you’ve done this you will be able to push your changes from the local repo to the remote.

Working with remotes – add / remove / details

Check the remote servers (or find git origin)

If you don’t know what the name is of your remote is then you can use this command to check :

git remote

You will then see the remote name of any servers.

Find out the name and url of the remote server

To find the url of ORIGIN use:

git remote -v

Change the remote url using git remote set-url

Use the git remote set-url command to change the url of the remote git repo. Similar to the git remote add command, git remote set-url takes 2 commands:

  • An existing remote name. For example, origin or myremote
  • A new URL for the remote. For example https://github.com/USERNAME/REPOSITORY.git

SO it would look like this:

git remote set-url ORIGIN^Cttps://github.com/EmilyChristy/react-bootstrap-cards.git
use git remote set-url to change remote url of the repor

Remove a remote from a git repository

Consider this scenario shown in the following image where I had accidentally set up two remotes, one called ORIGIN and called origin (bearing in mind that git is case sensitive).

Remove remote from git repo

I want to remove the lowercase version so I would use the following command :

git remote remove origin

You can see from the next image the result is correct, and we are now left with one remote in our git repository called ORIGIN.

Remote removed from git repository

Find out branch name in ORIGIN

To find details about a remote you can use this command:

git remote show ORIGIN 

… where ORIGIN is the name of the remote. You will see the url, the branch name, and will see which is the default branch.

FAQS

How to find git ORIGIN?

Use the git remote -v command

How do I set git ORIGIN?

You set git ORIGIN by using the git remote add command like this:
git remote add ORIGIN https://github.com/user/repo.git

How to remove a remote (ORIGIN) in git

You remove a remote by using:
git remote remove ORIGIN

What is the ORIGIN branch?

To find the default branch name in your remote (ORIGIN) you can use:
git remote show ORIGIN