Git

What is the Difference Between origin and upstream on GitHub?

On Git, to clone the repository and make a copy on the local machine from the GitHub server, then the users need to set the remote URL for tracking data from the centralized server. Once the remote URL is set, the developer doesn’t need to provide the path of the remote repository each time they perform the Git pull, push, or fetch operation.

The outcomes of this post are:

Differentiate Between upstream and origin on GitHub

The “origin” and “upstream” are both used as remote URL names. Sometimes users want to keep the default remote “origin”. They can add a new remote URL to the list for cloning another GitHub repository. Then, the “upstream” can be used for this purpose.

How to Add “origin” on GitHub?

To add the “origin” remote name to the list, follow the instructions below.

Step 1: Go to Root Directory

At first, switch to the root directory by utilizing the “cd” command:

$ cd "C:\Users\nazma\Git"

Step 2: Add Remote URL

Then, use the “git remote” command to add a new remote URL in the list for tracking the remote repository to the local repository:

$ git remote add origin https://github.com/GitUser0422/demo.git

Here, the “origin” is the name of our remote URL:

Step 3: Verify Remote URL

Next, to ensure that the newly added URL is placed in the remote list or not:

$ git remote -v

According to the below-given output, the previously added “origin” is added successfully:

How to Add “upstream” on GitHub?

To add another remote URL name with “upstream”, if the “origin” already exists in the list, execute the provided command:

$ git remote add upstream https://github.com/GitUser0422/demo3.git

Here, the “add” option will add the specified URL to the list:

Then, run the “git remote -v” command to verify the previously perform operation:

$ git remote -v

As you can see, the new remote URL named “upstream” is added successfully:

That’s all! We have briefly differentiated between the “upstream” and “origin” on GitHub.

Conclusion

When developers clone a remote repository, by default, it has a remote URL name called “origin” that points to their fork on GitHub. When developers want to keep the “origin” repository, they need to add another remote URL named “upstream”. This post differentiated between the “upstream” and “origin” on GitHub.

About the author

Maria Naz

I hold a master's degree in computer science. I am passionate about my work, exploring new technologies, learning programming languages, and I love to share my knowledge with the world.