Remote origin already exists git ошибка

The concept of remote is simply the URL of your remote repository.

The origin is an alias pointing to that URL. So instead of writing the whole URL every single time we want to push something to our repository, we just use this alias and run:

git push -u origin master

Telling to git to push our code from our local master branch to the remote origin repository.

Whenever we clone a repository, git creates this alias for us by default. Also whenever we create a new repository, we just create it our self.

Whatever the case it is, we can always change this name to anything we like, running this:

git remote rename [current-name] [new-name]

Since it is stored on the client side of the git application (on our machine) changing it will not affect anything in our development process, neither at our remote repository. Remember, it is only a name pointing to an address.

The only thing that changes here by renaming the alias, is that we have to declare this new name every time we push something to our repository.

git push -u my-remote-alias master

Obviously a single name can not point to two different addresses. That’s why you get this error message. There is already an alias named origin at your local machine. To see how many aliases you have and what are they, you can initiate this command:

git remote -v

This will show you all the aliases you have plus the corresponding URLs.

You can remove them as well if you like running this:

git remote rm my-remote-alias

So in brief:

  • find out what do you have already,
  • remove or rename them,
  • add your new aliases.

Happy coding.

Git fatal: remote origin already exists Печать

Добавил(а) microsin

  

Ключевое слово «origin» обычно используется для описания центрального источника (ресурса на сервере) репозитория Git. Если Вы попытаетесь добавить удаленный сервер (remote), так называемый «origin» к репозиторию, в котором описание origin уже существует, то получите ошибку «fatal: remote origin already exists». В этой статье (перевод [1]) мы обсудим подобный случай проблемы «fatal: remote origin already exists» и способ её решения.

Ошибка Git «fatal: remote origin already exists» показывает вам, что Вы пытаетесь создать remote с именем «origin», когда remote с таким именем уже существует (был прописан ранее). Это ошибка — общий случай, когда вы забыли, что уже настроили ссылку на remote репозиторий, и снова выполняете инструкции по установке. Также эту ошибку можно увидеть, если делается попытка поменять URL «origin» remote-репозитория командой git remote add.

Чтобы исправить эту ошибку, нужно сначала проверить, связан ли в настоящий момент remote с ключевым словом «origin», и что у него корректный URL. Вы можете сделать это командой git remote -v:

m:\asm\radiopager>git remote -v
origin  https://github.com/microsindotnet/git (fetch)
origin  https://github.com/microsindotnet/git (push)

Если «origin» URL не соответствует URL Вашего remote-репозитория, к которому Вы хотите обратиться, то можно поменять remote URL. Альтернативно можно удалить remote, и заново установить remote URL с именем «origin».

Пример проблемной ситуации. У нас есть некий репозиторий с именем «git», и мы хотим поменять его текущий origin:

https://github.com/microsindotnet/git

На новый origin:

https://github.com/microsindotnet/gitnew

Чтобы сделать это, мы используем команду git remote add command, который добавляет новый remote к репозиторию:

git remote add origin https://github.com/microsindotnet/gitnew

Но эта команда вернула ошибку:

fatal: remote origin already exists.

Этим сообщением git говорит нам, что remote origin уже существует.

Способ решения проблемы. Мы не можем добавить новый remote, используя имя, которое уже используется, даже если мы указываем для remote новый URL. В этом случае мы попытались создать новый remote с именем «origin», когда remote с таким именем уже существует. Чтобы исправить эту ошибку, мы должны удалить существующий remote, который называется «origin», и добавить новый, либо должны поменять URL существующего remote.

Чтобы удалить существующий remote и добавить новый, мы можем установить новый URL для нашего remote:

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

Это предпочтительный метод, потому что мы можем в одной команде поменять URL, связанный с нашим remote. Не понадобится уделить старый origin и создавать новый, потому что существует команда set-url.

Альтернативно мы можем удалить наш remote «origin», и после этого создать новый, с новым URL:

git remote rm origin
git remote add origin https://github.com/microsindotnet/gitnew

Этот метод использует 2 команды вместо одной.

[Ссылки]

1. Git fatal: remote origin already exists Solution site:careerkarma.com.
2. git: быстрый старт.

Do you write code for a living? Then learn Git, and learn it well. The tool originally created by Linus Torvalds—yes, the creator of the Linux kernel—has become the de facto standard when it comes to source control solutions. To help you along your learning journey, we’ve been covering common Git pitfalls and explaining how to get out of them. 

Today, we’ll add another installment to the series by covering an issue you might bump into when following Git tutorials over the web: the «remote origin already exists» error. As far as Git error messages go, this one is pretty straightforward, unlike other weirder messages. It clearly states what the problem is: you’re trying to add a remote called origin, but you already have one with that name. That’s not that different from your operating system preventing you from creating a file with the same name as an already existing file. 

In this post, we’ll give more detail into why that error message happens in the first place and then show you a few different ways in which you can address it. Let’s dig in. 

«Remote Origin Already Exists» Error: Why Does It Happen?

Picture this: You’re following a Git tutorial you’ve found online. So far everything works fine. Then, you see a line similar to the following one: 

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

After trying to execute the command above, you get the infamous error message: 

fatal: remote origin already exists.

Understanding this message is actually easy. Unlike centralized VCSs, Git doesn’t have a central server. In Git, you can have what we call remote repositories, or simply remotes. Remotes represent repositories that you might have read and/or write access to. Those are usually on machines other than your own, and you access them via SSH or HTTP. Keep in mind that, despite the name, remotes aren’t necessarily located on remote machines: despite sounding like an oxymoron, local remotes are totally possible. 

Remotes have names to identify them, and you can have as many remotes per repository as you need or want. However, you can’t have two remotes with the same name. So if you try to add a remote with the same name as an already existing remote, boom! Fatal error. 

If you want to be really sure the remote called origin actually exists, you can easily check that by running the following command: 

git remote

That will make your Git list all existing remotes for the current repository. If you want to get more detail, you can add the verbose parameter with the remote command, like this: 

git remote -v

That will return not only the names of each remote but also its URLs:

By the way, the message will not always contain the actual word «origin.» Let’s say you’re trying to add a remote called cloudbees but there’s already a remote with that name. In this case, the error message would say: 

fatal: remote cloudbees already exists.

Similarly to the way that the default branch in Git is called controller—though that could change in the near future—the default remote is called origin, but you could name it anything you like as long as it’s a legal name in Git. 

Solving the «Remote Origin Already Exists» Error in Four Different Ways

Having explained why the error message happens, we’ll now cover some of the several potential solutions you can use to solve the problem. Keep in mind that the solution you’ll use will depend on your specific situation because there are a few different scenarios that can cause this problem to happen. 

1. Remove the Existing Remote

The first scenario we’ll cover is the one in which there’s already a remote called origin, but it’s the wrong remote for some reason. Let’s say, for the sake of the example, that you used to use GitLab for storing your repositories online and then decided to switch over to GitHub (or vice versa). To go about that, you could follow the steps below: 

  1. Create a new repository online using GitHub or GitLab.

  2. Go to your local repository and remove the existing origin remote.

  3. Add the new online repository as the correct origin remote.

  4. Push your code to the new origin.

If, for some reason, you skip step #2, that will cause Git to display the «remote origin already exists» message. So a possible solution here would be simply removing the existing remote: 

git remote remove origin

As explained before, origin is just a name for a remote. It could be a different name for you. To make sure the remote is indeed deleted, you can use the Git remote command you saw earlier. Then, if everything is all right, you can go on to adding the desired remote. 

2. Update the Existing Remote’s URL

We’ve just shown you how to remove an existing remote, so you can hopefully add a new one, this time with the correct URL. However, you might be thinking that removing the remote and adding it again with a different link will have an eerily similar result as updating the URL of the existing remote. If that’s the case, you’re right, of course. 

So let’s see how to achieve the same result we got in the previous section but in a faster way. You just have to use a single command: 

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

As we’ve said before, we keep talking about origin throughout this post, but there’s nothing preventing you from working with whatever remote names you feel like. So a complete example with origin as the remote name and a URL to a real repo could look like this: 

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

3. Rename the Existing Remote

Let’s say that, for whatever reason, you already have a remote called origin. You want to add a new origin, but you also need to keep the old one. How would you go about it? 

Easy. Rename the existing remote before adding the new one. Just run the following command and you’re set: 

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

So let’s say you want to rename your origin remote to backup. You’d simply run: 

git remote rename origin backup

Then you can add your new remote called origin normally, and you should no longer see the «remote origin already exists» error. 

4. Do Nothing!

This is not a joke, I promise you. Here’s the thing: Sometimes, you might get the «remote origin already exists» error when following a tutorial that has some step asking you to add a remote called origin. If you try to run the command and get the error message, it’s possible that you’ve already executed that command and don’t remember. 

To check whether that’s really the case, you can use the Git remote command with the verbose option, as we’ve covered before: 

git remote -v

That will allow you to see the existing remotes along with the URLs they point to. If the existing remote already has the same URL provided by the tutorial, that means your repo is ready to go and you don’t need to do anything else. 

«Remote Origin Already Exists» Scaring You? A Thing of the Past

Git is an essential tool in the modern software developer’s tool belt. Unfortunately, many developers consider Git a hard tool to learn. There’s some truth to those claims. Though the basic Git commands you’ll use most of the time are easy to learn and understand, you might stumble upon a particularly difficult aspect of the tool from time to time. For instance, you might find yourself with a somewhat bizarre error message. Or the various ways in which Git allows you to go back and change things might trip you up a bit. 

In today’s post, we’ve covered a fairly common Git error message. Hopefully, you’re now ready to address this error when it comes your way. 

If there’s one takeaway you get from this post, we hope it’s this: Even though Git can sometimes feel daunting, it’s actually not that hard once you get used to some of its UI quirks and get somewhat familiar with its fundamentals. So keep studying and keep practicing, and then using Git will feel like second nature in no time. 

Learn to work with your local repositories on your computer and remote repositories hosted on GitHub.

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/OWNER/REPOSITORY.git

For example:

$ git remote add origin https://github.com/OWNER/REPOSITORY.git
# Set a new remote

$ git remote -v
# Verify new remote
> origin  https://github.com/OWNER/REPOSITORY.git (fetch)
> origin  https://github.com/OWNER/REPOSITORY.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/OWNER/REPOSITORY.git
    
    • If you’re updating to use SSH, your URL might look like:
    git@github.com:OWNER/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:OWNER/REPOSITORY.git (fetch)
    > origin  git@github.com:OWNER/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/OWNER/REPOSITORY.git
    
  5. Verify that the remote URL has changed.

    $ git remote -v
    # Verify new remote URL
    > origin  https://github.com/OWNER/REPOSITORY.git (fetch)
    > origin  https://github.com/OWNER/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 «Managing your personal access tokens.»

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/OWNER/REPOSITORY.git (fetch)
    > origin  https://github.com/OWNER/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:OWNER/REPOSITORY.git
    
  5. Verify that the remote URL has changed.

    $ git remote -v
    # Verify new remote URL
    > origin  git@github.com:OWNER/REPOSITORY.git (fetch)
    > origin  git@github.com:OWNER/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

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.

Понравилась статья? Поделить с друзьями:
  • Remote logins are currently disabled ошибка
  • Restraint system bmw e60 как убрать ошибку
  • Resident evil 7 biohazard неисправимая ошибка
  • Rest api wordpress ошибка
  • Remote key battery e39 ошибка