'Can a project have multiple origins?
Can a project have two (or more) "origins" in Git?
I would like to push a single project to both github and a Heroku server.
Specifically, this error appears when adding the github repository:
$ git remote add origin https://github.com/Company_Name/repository_name.git
fatal: remote origin already exists.
Solution 1:[1]
Of note it is possible to have origin push to more than one git repository server at a time.
One can achieve this by using the following command to add another URL to the origin remote.
git remote set-url --add origin ssh://[email protected]/user/myproject.git
Solution 2:[2]
Here's a sample project with multiple remotes, GitHub & GitLab:
Add remote repo for GitHub
$ git remote add github https://github.com/Company_Name/repository_name.gitAdd remote repo for GitLab
$ git remote add gitlab https://gitlab.com/Company_Name/repository_name.gitNow you have multiple remotes in the project. Double check with
git remote -v$ git remote -v github https://github.com/Company_Name/repository_name.git (fetch) github https://github.com/Company_Name/repository_name.git (push) gitlab https://gitlab.com/Company_Name/repository_name.git (fetch) gitlab https://gitlab.com/Company_Name/repository_name.git (push)How do you push to multiple repositories?
$ git push github && git push gitlab
Solution 3:[3]
git remote set-url --add --push origin [email protected]:user/my-project.git
git remote set-url --add --push origin [email protected]:user/my-project.git
Now you have 2 origins.
Solution 4:[4]
A local repository can be linked to multiple remote repositories.
However only one of those links can be called origin. The rest of the links need to have different names.
Therefore in order to properly answer this questions we need to understand what origin is.
Let me explain with an example.
Supposed 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. 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 you can see that I used the shortname friend to refer to my friend's remote repository. You 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!
There is a really helpful video ? that explains all of this that can be found here.
Solution 5:[5]
you can add another remote account to your repository through giving different name instead of origin. You can use name such as origin2. so your git command can be modified as
git remote add origin2 https://github.com/Company_Name/repository_name.git
Solution 6:[6]
git remote add origin2 https://github.com/Company_Name/repository_name.git
and for push use:
git push -u origin2 master
Solution 7:[7]
You can follow the following steps to push your changes in new remote from existing repository.
cd existing_repo
Rename your current remote (optional)
git remote rename origin old-origin
Add new remote (used origin here)
git remote add origin https://github.com/repository_name.git
Now you can push your code to the new origin remote
git push -u origin --all
git push -u origin --tags
Solution 8:[8]
You can use Instead of origin use GitHub or GitLab
for github in place of origin use github
git remote add github https://github.com/repository_name.git
git push github branchname
for gitlab in place of origin use gitlab
git remote add gitlab https://github.com/repository_name.git
git push gitlab branchname
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | ΩmegaMan |
| Solution 2 | Michael |
| Solution 3 | Ostap Brehin |
| Solution 4 | Anna Skoulikari |
| Solution 5 | dinith jayabodhi |
| Solution 6 | Armel |
| Solution 7 | Animesh Rawat |
| Solution 8 | MD SHAYON |



