Error remote target already exists

How to fix ‘fatal: remote origin already exists’ Git error Learning objective What is the ‘fatal: remote origin already exists’ error? fatal: remote origin already exists is a common Git error that occurs when you clone a repository from GitHub, or an external remote repository, into your local machine and then try to update […]

Содержание

  1. How to fix ‘fatal: remote origin already exists’ Git error
  2. Learning objective
  3. What is the ‘fatal: remote origin already exists’ error?
  4. What is a remote origin in Git?
  5. Detect and fix errors 5x faster
  6. Resolving ‘fatal: remote origin already exists’
  7. 1. Remove the Existing Remote
  8. 2. Update the Existing Remote’s URL
  9. 3. Rename the Existing Remote
  10. How to prevent ‘fatal: remote origin already exists’
  11. K8s troubleshooting with Komodor
  12. Git error — Fatal: remote origin already exists and how to fix it
  13. «Remote origin already exists» error
  14. What is a remote repository?
  15. How does the «remote» tool work?
  16. “origin” is a convention, not a part of the `git remote` command
  17. Remote “origin” might’ve been configured if you cloned the repo
  18. Conclusion
  19. Learn from Nana, AWS Hero & CNCF Ambassador, how to enforce K8s best practices with Datree
  20. рџЌї Techworld with Nana: How to enforce Kubernetes best practices and prevent misconfigurations from reaching production. Watch now.
  21. Headingajsdajk jkahskjafhkasj khfsakjhf

How to fix ‘fatal: remote origin already exists’ Git error

Learning objective

What is the ‘fatal: remote origin already exists’ error?

fatal: remote origin already exists is a common Git error that occurs when you clone a repository from GitHub, or an external remote repository, into your local machine and then try to update the pointing origin URL to your own repository.

In the context of Kubernetes, the error can occur when you configure orchestrations to include Git repositories. For example, by using: git remote add origin [url].gits

fatal: remote origin already exists is caused by the cloned repository already having a URL configured. Specifically, a URL that leads to the original profile where the repository source is.

What is a remote origin in Git?

remote origin , as the name implies, is the place where code is stored remotely. It is the centralized server or zone where everyone pushes code to and pulls code from.

Remote repositories are versions of your project hosted on Git-compatible platforms such as GitHub, Bitbucket, GitLab, and Assembla. origin is the standard and generic handle that is used to associate the host site’s URL.

For example, you can have an alternative remote URL called dev , which then becomes the handle for a separate repository but for the same code.

When you run git remote -v , you will get a list of handles and associated URLs. So if you have different handlers for the same remote, the console output could look something like this:

This means that you can run the following command: git push dev master

The changes made will get pushed up to the master branch at the URL associated with dev and not origin .

Detect and fix errors 5x faster

Komodor monitors your entire K8s stack, identifies issues, and uncovers their root cause.

Resolving ‘fatal: remote origin already exists’

For most development environments, origin is the default handler used. Here are 3 ways to resolve fatal: remote origin already exists .

1. Remove the Existing Remote

remote refers to the hosted repository. origin is the pointer to where that remote is. Most of the time, origin is the only pointer there is on a local repository.

If you want to change the pointing URL attached to origin , you can remove the existing origin and then add it back in again with the correct URL.
To remove your handler, use the remove command on remote , followed by the handler name – which, in our case, is origin .
Here is an example: git remote remove origin

To check that handler is deleted properly, run the following: git remote -v

You will either get an empty list, or you will get a list of remote handlers that are currently attached to the project with origin removed from the list.
Now you can run git remote add origin [url].git without encountering the fatal: remote origin already exists error.

2. Update the Existing Remote’s URL

You are not always required to remove the origin handler from remote . An alternative way to solve fatal: remote origin already exists is to update the handler’s pointing URL.

To do this, you can use the set-url command, followed by the handler name (which is origin in our case) and the new URL.

Here is the syntax for updating an existing origin URL: git remote set-url origin [new-url]

Once this is completed, you can now push and pull code from the newly configured Git repository location.

3. Rename the Existing Remote

Alternatively, you can rename origin to something else. This means that instead of deleting the handler’s pointing URL to make room for the new one, you can rename it and keep the original details.

To do this, use the rename command on: remote .

For example, if you want to rename origin to dev , you can use the following command: git remote rename origin dev

Now when you run git remote -v , you will get dev as the handler instead of origin .

This will give you room to add a new origin to the list of attached handlers. So when you run git remote add origin [url].git , you will no longer get the fatal: remote origin already exists error prompt.

How to prevent ‘fatal: remote origin already exists’

To prevent fatal: remote origin already exists error from occurring, you can check if the origin handler already exists. If it does not, running the git add remote origin command should not produce this issue.

The most important thing to note here is that origin is only a handler’s short name. It is a reference to the URL, which is where the actual remote repository is hosted.

The handler origin just happens to be the standardized default. This is what makes fatal: remote origin already exists so common. The error itself can occur against any handler, provided that it has the same placeholder name.

To check if origin even exists, run git remote -v to get a list of current remote handlers and the associated URLs.

If origin exists, you can do one of the following:

  • remove origin from the remote list via remove command, like so: git remote remove origin
  • update origin pointing URL with set-url , like so: git remote set-url origin [new-url]
  • rename the existing origin handler to something else via rename command: git remote rename origin [new-name]

K8s troubleshooting with Komodor

We hope that the guide above helps you better understand the troubleshooting steps you need to take in order to fix the fatal: remote origin already exists error.

Keep in mind that this is just one of many Git errors that can pop up in your k8s logs and cause the system to fail. Due to the complex and distributed nature of k8s,
the search for the root cause of each such failure can be stressful, disorienting and time-consuming.

This is why we created Komodor, which acts as a single source of truth (SSOT) to streamline and shorten your k8s troubleshooting processes. Among other features, it offers:

Источник

Git error — Fatal: remote origin already exists and how to fix it

«Remote origin already exists» error

The error `fatal: remote origin already exists` is caused when you attempt to create a link to a remote repository called “origin” when a remote link with that name is already configured.

The solution is to update the URL of the remote repository with the name “origin” to the URL of the remote repository you want to add, instead of trying to create a new remote repository with that name.

You can do that with this command:

‍
It’s possible to inadvertently configure your local repository wrong if you don’t totally get what the commands that you’re running mean, or if you cloned a repository that already has a remote with the name “origin” configured.

To help you avoid making this mistake again, let’s unpack the concept of remote repositories a little. This error is usually caused by misunderstanding one of several things: what a remote repository is, how the `remote` command works, or more specifically what “origin” part of these commands means.

What is a remote repository?

To understand what a remote repository is, it’s important to first understand that Git stores and operates on your data in your local file system. In fact, Git is referred to as a distributed version control system because the source code is stored, or distributed, locally across any number of computers and servers. This is different from many of the source control tools that preceded Git.

Those tools were known as centralized version control systems (SVN or Subversion are the most well known examples), and they only operated on data hosted on a server by uploading changes in real time.

This meant that everybody always had access to the same data, because they were all working from the same server, but changes were slow to update and relied on a stable internet connection at all times.

Because all work stored in a Git repository lives in your local file system, source control operations are blazing fast and don’t require an internet connection, since you don’t upload each change to a server as it happens. The tradeoff is that your code isn’t easily accessible to others, so you need to regularly upload your changes to a server in order for other people to access them.

This is where remote repositories, or remotes, come in. A remote repository is a Git repository that lives on a server and is set up to be a mirror of your local work. Every time you run the `git push` command, you push your latest changes into that remote repository. Then, when somebody pulls from that remote repository, they receive your changes and end up with the same code you have.

This means that your code usually lives in multiple places — in your local Git repository, in the remote one living on the server (GitHub is the most well known server), and in the file system of anybody else who has downloaded your work from the remote repository into a local repository of their own.

In a nutshell, a remote repository is where you upload your locally stored changes so that others can access them.

Now that we’ve covered what a remote repository is and why it’s necessary, it’s time to talk about how you can attach one to your local repository. Usually, this isn’t something that happens automatically — you need to configure remotes by hand

Git’s `remote` tool provides a number of commands to configure remotes: add, remove, rename, etc. You can read the full documentation here, but for the purposes of solving the error this article is about, we are going to be most concerned with “add”, “remove”, and “reset-url”.

Let’s cover the few specific use-cases relevant to us briefly below:

git remote add is going to be the most commonly used command. This is how you can attach a remote to your repository. It associates the “url” parameter with the “name” you pass in. Looks like this, as you probably already know:

git remote remove is pretty self-explanatory, and is also used frequently. If you don’t want to have a particular remote attached to your repository, just pass its name to this command and that remote will be completely removed. It won’t persist in history, caching or anywhere else:

In theory, you could remove the `origin` remote and then re-add it, but instead of doing that in two steps, you can actually knock it out in just one with the `set-url` command that I showed you at the top of this article. In one step, this command will update the URL of a repository for the given name you pass in.

Just for an example, if we were to list the remotes with `git remote —verbose` before and after running this command, they might look like this:

Let’s run the `set-url` command:

‍
And looking at the list again:

“origin” is a convention, not a part of the `git remote` command

It’s worth noting that using “origin” for the name of your default remote repository is simply a convention — you could name your default remote “cheese” for all the difference it would make.

It’s frustrating, because this convention is actually the primary source of remote naming errors. At first glance it’s not obvious whether “origin” is part of the `git remote` command or just a parameter, a misconception that is further supported by the wording of the Git error: it’s not obvious that “origin” is a parameter, and not a part of the failing command.

And yes, this means that the error thrown at the top of the article could just as easily read “fatal: remote cheese already exists.”

Remote “origin” might’ve been configured if you cloned the repo

Since “origin” is such a common convention, there’s a good chance that any repository you clone already has a remote configured with this name, because remotes are included when a repository is cloned.‍

Cloning a repository and trying to add your own remote server to “origin” without realizing that that name is already in use is a very common way this error is caused. And again — the solution is to use `git remote set-url` instead of `git remote add`.

Conclusion

As I mentioned at the beginning of this article, we broke down the concept of remote repositories in Git and went over a few of the most common commands that you’ll need to understand in order to use them properly. For further reading, you can find formal documentation on the `git remote` command here.

Nota bene: It’s easy to just copy and paste random bits of code that you find on Google to quickly fix the error, but generally speaking it’s much more useful to understand the underlying concepts so that you don’t have to keep Googling the same commands over and over again. So, if anything is still confusing, I’d encourage you to re-read this article and dig into the documentation linked above, as well as try out the examples and everything else you find for yourself.В

I hope this helps, and good luck!

Learn from Nana, AWS Hero & CNCF Ambassador, how to enforce K8s best practices with Datree

рџЌї Techworld with Nana: How to enforce Kubernetes best practices and prevent misconfigurations from reaching production. Watch now.

Headingajsdajk jkahskjafhkasj khfsakjhf

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse varius enim in eros elementum tristique. Duis cursus, mi quis viverra ornare, eros dolor interdum nulla, ut commodo diam libero vitae erat. Aenean faucibus nibh et justo cursus id rutrum lorem imperdiet. Nunc ut sem vitae risus tristique posuere.

Источник

What is the ‘fatal: remote origin already exists’ error?

fatal: remote origin already exists is a common Git error that occurs when you clone a repository from GitHub, or an external remote repository, into your local machine and then try to update the pointing origin URL to your own repository.

In the context of Kubernetes, the error can occur when you configure orchestrations to include Git repositories. For example, by using: git remote add origin [url].gits

fatal: remote origin already exists is caused by the cloned repository already having a URL configured. Specifically, a URL that leads to the original profile where the repository source is.

What is a remote origin in Git?

remote origin, as the name implies, is the place where code is stored remotely. It is the centralized server or zone where everyone pushes code to and pulls code from.

Remote repositories are versions of your project hosted on Git-compatible platforms such as GitHub, Bitbucket, GitLab, and Assembla. origin is the standard and generic handle that is used to associate the host site’s URL.

For example, you can have an alternative remote URL called dev, which then becomes the handle for a separate repository but for the same code.

When you run git remote -v, you will get a list of handles and associated URLs. So if you have different handlers for the same remote, the console output could look something like this:

D:GitHubgit remote -v
origin  https://github.com/prod_repo/projectx.git (fetch)
origin  https://github.com/prod_repo/projectx.git (push)
dev     https://github.com/dev_repo/projectx.git (fetch)
dev     https://github.com/dev_repo/projectx.git (push)  

This means that you can run the following command: git push dev master

The changes made will get pushed up to the master branch at the URL associated with dev and not origin.

Resolving ‘fatal: remote origin already exists’

For most development environments, origin is the default handler used. Here are 3 ways to resolve fatal: remote origin already exists.

1. Remove the Existing Remote

remote refers to the hosted repository. origin is the pointer to where that remote is. Most of the time, origin is the only pointer there is on a local repository.

If you want to change the pointing URL attached to origin, you can remove the existing origin and then add it back in again with the correct URL.
To remove your handler, use the remove command on remote, followed by the handler name – which, in our case, is origin.
Here is an example: git remote remove origin

To check that handler is deleted properly, run the following: git remote -v

You will either get an empty list, or you will get a list of remote handlers that are currently attached to the project with origin removed from the list.
Now you can run git remote add origin [url].git without encountering the fatal: remote origin already exists error.

2. Update the Existing Remote’s URL

You are not always required to remove the origin handler from remote. An alternative way to solve fatal: remote origin already exists is to update the handler’s pointing URL.

To do this, you can use the set-url command, followed by the handler name (which is origin in our case) and the new URL.

Here is the syntax for updating an existing origin URL: git remote set-url origin [new-url]

Once this is completed, you can now push and pull code from the newly configured Git repository location.

3. Rename the Existing Remote

Alternatively, you can rename origin to something else. This means that instead of deleting the handler’s pointing URL to make room for the new one, you can rename it and keep the original details.

To do this, use the rename command on: remote.

For example, if you want to rename origin to dev, you can use the following command: git remote rename origin dev

Now when you run git remote -v, you will get dev as the handler instead of origin.

D:GitHub[some-repo]git remote -v
dev     https://github.com/some_repo/projectx.git (fetch)
dev     https://github.com/some_repo/projectx.git (push)  

This will give you room to add a new origin to the list of attached handlers. So when you run git remote add origin [url].git, you will no longer get the fatal: remote origin already exists error prompt.

How to prevent ‘fatal: remote origin already exists’

To prevent fatal: remote origin already exists error from occurring, you can check if the origin handler already exists. If it does not, running the git add remote origin command should not produce this issue.

The most important thing to note here is that origin is only a handler’s short name. It is a reference to the URL, which is where the actual remote repository is hosted.

The handler origin just happens to be the standardized default. This is what makes fatal: remote origin already exists so common. The error itself can occur against any handler, provided that it has the same placeholder name.

To check if origin even exists, run git remote -v to get a list of current remote handlers and the associated URLs.

If origin exists, you can do one of the following:

  • remove origin from the remote list via remove command, like so: git remote remove origin
  • update origin pointing URL with set-url, like so:git remote set-url origin [new-url]
  • rename the existing origin handler to something else via rename command: git remote rename origin [new-name]

K8s troubleshooting with Komodor

We hope that the guide above helps you better understand the troubleshooting steps you need to take in order to fix the fatal: remote origin already exists error.

Keep in mind that this is just one of many Git errors that can pop up in your k8s logs and cause the system to fail. Due to the complex and distributed nature of k8s,
the search for the root cause of each such failure can be stressful, disorienting and time-consuming.

This is why we created Komodor, which acts as a single source of truth (SSOT) to streamline and shorten your k8s troubleshooting processes. Among other features, it offers:

  • Change intelligence: Every issue is a result of a change. Within seconds we can help you understand exactly who did what and when.
  • In-depth visibility: A complete activity timeline, showing all code and config changes, deployments, alerts, code diffs, pod logs and etc. All within one pane of glass with easy drill-down options.
  • Insights into service dependencies: An easy way to understand cross-service changes and visualize their ripple effects across your entire system.
  • Seamless notifications: Direct integration with your existing communication channels (e.g., Slack) so you’ll have all the information you need, when you need it.

Adding a remote repository

To add a new remote, use the git remote add command on the terminal, in the directory your repository is stored at.

The git remote add command takes two arguments:

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

For example:

$ git remote add origin https://github.com/USER/REPO.git
# Set a new remote

$ git remote -v
# Verify new remote
> origin  https://github.com/USER/REPO.git (fetch)
> origin  https://github.com/USER/REPO.git (push)

For more information on which URL to use, see «About remote repositories.»

Troubleshooting: Remote origin already exists

This error means you’ve tried to add a remote with a name that already exists in your local repository.

$ git remote add origin https://github.com/octocat/Spoon-Knife.git
> fatal: remote origin already exists.

To fix this, you can:

  • Use a different name for the new remote.
  • Rename the existing remote repository before you add the new remote. For more information, see «Renaming a remote repository» below.
  • Delete the existing remote repository before you add the new remote. For more information, see «Removing a remote repository» below.

Changing a remote repository’s URL

The git remote set-url command changes an existing remote repository URL.

The git remote set-url command takes two arguments:

  • An existing remote name. For example, origin or upstream are two common choices.
  • A new URL for the remote. For example:
    • If you’re updating to use HTTPS, your URL might look like:
      https://github.com/USERNAME/REPOSITORY.git
    • If you’re updating to use SSH, your URL might look like:
      git@github.com:USERNAME/REPOSITORY.git

Switching remote URLs from SSH to HTTPS

  1. Open TerminalTerminalGit Bash.
  2. Change the current working directory to your local project.
  3. List your existing remotes in order to get the name of the remote you want to change.
    $ git remote -v
    > origin  git@github.com:USERNAME/REPOSITORY.git (fetch)
    > origin  git@github.com:USERNAME/REPOSITORY.git (push)
  4. Change your remote’s URL from SSH to HTTPS with the git remote set-url command.
    $ git remote set-url origin https://github.com/USERNAME/REPOSITORY.git
  5. Verify that the remote URL has changed.
    $ git remote -v
    # Verify new remote URL
    > origin  https://github.com/USERNAME/REPOSITORY.git (fetch)
    > origin  https://github.com/USERNAME/REPOSITORY.git (push)

The next time you git fetch, git pull, or git push to the remote repository, you’ll be asked for your GitHub username and password. When Git prompts you for your password, enter your personal access token. Alternatively, you can use a credential helper like Git Credential Manager. Password-based authentication for Git has been removed in favor of more secure authentication methods. For more information, see «Creating a personal access token.»

You can use a credential helper so Git will remember your GitHub username and personal access token every time it talks to GitHub.

Switching remote URLs from HTTPS to SSH

  1. Open TerminalTerminalGit Bash.
  2. Change the current working directory to your local project.
  3. List your existing remotes in order to get the name of the remote you want to change.
    $ git remote -v
    > origin  https://github.com/USERNAME/REPOSITORY.git (fetch)
    > origin  https://github.com/USERNAME/REPOSITORY.git (push)
  4. Change your remote’s URL from HTTPS to SSH with the git remote set-url command.
    $ git remote set-url origin git@github.com:USERNAME/REPOSITORY.git
  5. Verify that the remote URL has changed.
    $ git remote -v
    # Verify new remote URL
    > origin  git@github.com: USERNAME/REPOSITORY.git (fetch)
    > origin  git@github.com: USERNAME/REPOSITORY.git (push)

Troubleshooting: No such remote ‘[name]’

This error means that the remote you tried to change doesn’t exist:

$ git remote set-url sofake https://github.com/octocat/Spoon-Knife
> fatal: No such remote 'sofake'

Check that you’ve correctly typed the remote name.

Renaming a remote repository

Use the git remote rename command to rename an existing remote.

The git remote rename command takes two arguments:

  • An existing remote name, for example, origin
  • A new name for the remote, for example, destination

Example of renaming a remote repository

These examples assume you’re cloning using HTTPS, which is recommended.

$ git remote -v
# View existing remotes
> origin  https://github.com/OWNER/REPOSITORY.git (fetch)
> origin  https://github.com/OWNER/REPOSITORY.git (push)

$ git remote rename origin destination
# Change remote name from 'origin' to 'destination'

$ git remote -v
# Verify remote's new name
> destination  https://github.com/OWNER/REPOSITORY.git (fetch)
> destination  https://github.com/OWNER/REPOSITORY.git (push)

Troubleshooting: Could not rename config section ‘remote.[old name]’ to ‘remote.[new name]’

This error means that the old remote name you typed doesn’t exist.

You can check which remotes currently exist with the git remote -v command:

$ git remote -v
# View existing remotes
> origin  https://github.com/OWNER/REPOSITORY.git (fetch)
> origin  https://github.com/OWNER/REPOSITORY.git (push)

Troubleshooting: Remote [new name] already exists

This error means that the remote name you want to use already exists. To solve this, either use a different remote name, or rename the original remote.

Removing a remote repository

Use the git remote rm command to remove a remote URL from your repository.

The git remote rm command takes one argument:

  • A remote name, for example, destination

Removing the remote URL from your repository only unlinks the local and remote repositories. It does not delete the remote repository.

Example of removing a remote repository

These examples assume you’re cloning using HTTPS, which is recommended.

$ git remote -v
# View current remotes
> origin  https://github.com/OWNER/REPOSITORY.git (fetch)
> origin  https://github.com/OWNER/REPOSITORY.git (push)
> destination  https://github.com/FORKER/REPOSITORY.git (fetch)
> destination  https://github.com/FORKER/REPOSITORY.git (push)

$ git remote rm destination
# Remove remote
$ git remote -v
# Verify it's gone
> origin  https://github.com/OWNER/REPOSITORY.git (fetch)
> origin  https://github.com/OWNER/REPOSITORY.git (push)

Note: git remote rm does not delete the remote repository from the server. It simply
removes the remote and its references from your local repository.

Troubleshooting: Could not remove config section ‘remote.[name]’

This error means that the remote you tried to delete doesn’t exist:

$ git remote rm sofake
> error: Could not remove config section 'remote.sofake'

Check that you’ve correctly typed the remote name.

Further reading

  • «Working with Remotes» from the Pro Git book

fatal: remote origin already exists” problem, you get this git error when you try to create a link to a remote repository called “origin” when another remote repository with that name already exists.

The answer is to alter the URL of the remote repository with the name “origin” to the URL of the remote repository you want to add, rather than trying to establish a new remote repository with the name “origin.”

You can do so with the following command:

git remote set-url origin https://github.com/your/repository 

You may configure your local repository wrong if you don’t completely comprehend the instructions you’re doing, or if you cloned a repository that already has a remote with the name “origin” configured.

Let’s take a closer look at remote repositories so you don’t make the same mistake again. The most typical cause of this problem is a misunderstanding of one or more of the following: what a remote repository is, how the remote command works, or, more specifically, what the “origin” aspect of these instructions means.

Why Does the «Remote Origin Already Exists» Error Occur?

Consider the following scenario: You’re working through a Git instruction that you discovered online. So far, everything has gone smoothly. Then you come upon a line that looks like this:

git remote add origin <Your-URL>/<Your-REPOSITORY-NAME>.git 

When you try to run the command above, you get the dreaded error message:

fatal: remote origin already exists. 

This message is actually quite simple to comprehend. Git does not have a central server, unlike centralized VCSs. Remote repositories, or simply remotes, are what we call them in Git. Remotes are repositories to which you may have read and/or write permissions.

These are normally located on machines other than your own, and you can connect to them using SSH or HTTP. Keep in mind that, despite their name, remotes aren’t always found on remote machines: local remotes, although sounding like an oxymoron, are entirely feasible.

Remotes have names to help you recognise them, and you can have as many as you need or wish per repository. You can’t have two remotes with the same name, though. So, if you try to add a remote with the same name as an existing remote, you’ll get an error message. A fatal blunder.

If you wish to double-check if the remote called origin exists, use the following command:

This will cause your Git to display a list of all available remotes for the current repository. If you want extra information, use the verbose parameter with the remote command, such as this:

This will yield the names of each remote as well as their URLs:

origin	https://github.com/your/repository (fetch)
origin	https://github.com/your/repository (push) 

By the way, the phrase “origin” will not always appear in the message. Assume you’re trying to add a codeleaks remote, but there’s already one with that name. The error message in this scenario would be:

fatal: remote codeleaks already exists. 

The default remote is called origin, just like the default branch in Git is called controller—though that could change in the near future—but you can call it anything you want as long as it’s a legal Git name.

Four Approaches to Resolving the «Remote Origin Already Exists» Error

After explaining why, the error notice appears, we’ll go over some of the possible strategies for resolving the issue. Keep in mind that the remedy you choose will be dependent on your individual situation because this problem can occur in a variety of ways.

Approach 01: Remove the Remote that already exists

The first example we’ll look at is when a remote called origin already exists, but it’s the wrong remote for whatever reason. Let’s pretend you were previously using GitLab to store your online repositories and then switched to GitHub (or vice versa). You could do so by following the instructions below:

  • Using GitHub or GitLab, create a newbit online repository.
  • Remove the existing origin remote from your local repository.
  • Assign the correct origin remote to the new online repository.
  • Your code will be pushed to the new origin.

If you omit step #2 for whatever reason, Git will display the “remote origin already exists” message. As a result, simply deleting the existing remote could be a viable option:

As previously stated, origin is simply a term for a distant. For you, it could be a different name. You can use the Git remote command, which you saw before, to verify that the remote has been destroyed. After that, if everything looks good, you can proceed to adding the chosen remote.

Approach 02: Update the URL of Existing Remote

We just showed you how to remove an existing remote, so perhaps you can install a new one with the correct URL this time. However, you may believe that removing the remote and re-adding it with a different link will have a result that is eerily similar to changing the URL of the original remote. Of course, if that’s the case, you’re correct.

So, let’s see how we can get the same outcome as we did in the previous section, but in a shorter amount of time. You only need to use one command:

git remote set-url <REMOTE-NAME> <NEW-URL> 

We’ve already mentioned that we’ll be talking about origin throughout this post, but there’s nothing stopping you from using whatever remote names you choose. So, using origin as the remote name and a URL to a real repo, a complete example may look like this:

git remote set-url origin https://github.com/git/git.git 

Approach 03: Rename the Remote that already exists

Let’s imagine you already have a remote called origin for any reason. You’d want to add a new origin, but you’d like to maintain the previous one as well. What would you do if you had to do it?

Easy. Before you add the new remote, rename the old one. All you have to do now is run the following command:

git remote rename <old-name> <new-name> 

Let’s imagine you wish to rename your backup remote to origin remote. You’d simply take off:

git remote rename origin backup 

Then you can add your new remote called origin as usual, and the “remote origin already exists” error should be gone.

Approach 04: Don’t need to do Anything

I promise you, this isn’t a joke. But here’s the deal: When following a tutorial with a step that asks you to add a remote called origin, you may get the “remote origin already exists” issue. If you try to run the command and receive an error message, it’s possible you’ve previously done it and aren’t aware of it.

You can use the Git remote command with the verbose option to see if that’s the case, as we’ve seen before:

You’ll be able to see all of the existing remotes, as well as the URLs they link to. If the existing remote already has the same URL as the tutorial, your repo is ready to use and there is no need to do anything else.

«Remote Origin Already Exists» Nothing to get Panic

Git is a must-have in the toolkit of any modern software engineer. Unfortunately, many engineers regard Git as a difficult technology to master. Those assertions include some truth.

Though the most common Git commands are simple to learn and understand, you may come into a particularly challenging component of the tool from time to time. You might, for example, receive a strange error message. Or you can be tripped up by the different ways Git allows you to go back and tweak things.

Conclusion

In conclusion, we discussed how to fix the git error fatal: remote origin already exists. We deconstructed the notion of Git remote repositories and went over a few of the most frequent commands you’ll need to know in order to use them effectively.

Fix for git fatal: remote origin already exists error

This article discusses how to resolve the issue git fatal: remote origin already exists error during the push or add commands.

Fix git fatal: remote origin already exists error on push

You must run the ‘git init’ command to enable git for any application or folder/directory.

Once git is initialized, we must either create a new repository or clone an existing repository to map this to the existing directory.

if this directory is created in the nested folder of any git repository, the git command throws git fatal: remote origin already exists error.

fatal: remote origin already exists git error

What does its origin mean?

This error comes during multiple use cases.

  • created a local nested folder app, It is a child folder of a local git repository, these folders map to the new remote repository.
B:blogjswork>git remote add origin https://github.com/intkiran/react-auth0-login.git
fatal: remote origin already exists.

An error would

fatal: remote origin already exists.

From the above code, It creates an origin local name and adds it to an existing repository.

In any local repository, How do you know the remote repository url?
using the -v option gives the local name with a remote url as described following

And the output is

origin  https://github.com/intkiran/react-auth0-login.git (fetch)
origin  https://github.com/intkiran/react-auth0-login.git (push)

It gives the remote repository url mapped with the local name i.e origin.

Origin is the local name for the remote repository given by default.

This error occurs after adding a new url to the existing origin.

This post covers the solution for the following errors in the git command

  • fatal: No such remote:
  • Remote origin already exists on ‘git push’ to a new repository

There are many ways we can fix this.

Remove the original name from the given existing repository

First, delete the local name origin for a given remote repository using the following command.

next, add the original name to the new remote repository

git remote add origin remote-repo-url

set-url Change origin name from the given existing git repository

git remote set-url neworigin remote-repo-url

if remote-repo-url does not exist, it gives an error fatal: No such remote:.

Replace current origin with new url in Git

below set the new url for the local name origin.

git remote set-url origin remote-repo-url

rename existing origin name in Git

The last approach is to rename the existing origin to the new name

git remote rename origin neworigin

Finally, Verify the name mapped to the URLs using the below command.

wrap

There are many ways we can fix these errors with the above solutions.

Понравилась статья? Поделить с друзьями:
  • Error remote origin already exists что значит
  • Error remote origin already exists переводчик
  • Error referenceerror regeneratorruntime is not defined
  • Error referenceerror localstorage is not defined
  • Error remote origin already exists перевод