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.

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
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:asmradiopager>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: быстрый старт.

A good version control system is critical for the software development life cycle to manage and streamline the development and deployment processes properly. Git is the leading version control system powering numerous projects from simple hobby projects to enterprise-grade applications.

As with any other software system, users may encounter errors while using Git for source code management. This article will discuss how to fix the git error: “fatal: remote origin already exists.”

What is fatal: remote origin already exists Error?

Users will face this error while attempting to create a remote with the name “origin” when a remote with this name already exists within the git repository. Since Git is a distributed version control system, the data is stored locally until the code is pushed to a remote repository. This error occurs when a user tries to link a remote git repository with the local repo using the git remote tool.

The “origin” in this error refers to the name of the remote. If there is a remote named “test” in the repository and a user is trying to add a remote with the same name, it will generate the following error;

fatal: remote test already exists

Enter fullscreen mode

Exit fullscreen mode

The name “origin” refers to the default remote, and users can use any name as long as it is compatible with Git. However, the best practice is to adhere to the Git naming convention when naming git branches.

Common Causes for fatal: remote origin already exists Error

Newcomers to Git will encounter this error if they try to set up an already existing repository. This is common if the user is trying to follow along with a tutorial without knowing that they have already linked the remote repository or simply forgot that the local repository is already linked to the remote repository (remote “origin” already configured).

Another reason is trying to change the URL of the “origin” remote repository using the git remote add command. The remote add command will attempt to create a new link between the local and the remote repo, and it will create the “fatal: remote origin already exists error” if there is an existing configuration.

How to Fix the fatal: remote origin already exists Error

Since now we have a clear understanding of this error, let’s see how to mitigate it. Users need to identify any existing remotes before trying to apply a fix. This can be done by running the git remote command within the local git directory.

git remote -v

Enter fullscreen mode

Exit fullscreen mode

Alt Text

The output will show any remotes in the repository with both the remote name and the remote URL. If the output matches the required configuration, users should not do anything further as the remote is already configured.

If the output of the remote command is invalid, one of the following methods can be utilized to fix this error.

Update the URL
Sometimes the user needs to simply update the remote URL so that the specific remote will point to a different URL. We can do this using the remote set-url command. In the below example, we are updating the URL of the remote named “origin.”

git remote set-url <remote-name>  <new-remote-url>

Enter fullscreen mode

Exit fullscreen mode

Alt Text

Now, if we check the remotes using the git remote command, it will reflect the updated URL.

Alt Text

The most important fact to remember here is to point to the correct remote name and URL, or otherwise, it will cause conflicts with the existing code in the repositories.

Completely Removing the Existing Remote
Users can simply remove the existing remote and then re-add the remote. To remove an existing remote, we can use the remote remove command with the specific remote name.

git remote remove <remote-name>

Enter fullscreen mode

Exit fullscreen mode

Let’s assume that we already have a remote called “origin” in a git repository. We can remove that remote using the following command.

Alt Text

After removing, we can re-add the remote to the git repository with the same name. It will not encounter the remote origin already exists error since there are no conflicting remotes.

git remote add origin https://github.com/xxxxxxxx/test_application.git

Enter fullscreen mode

Exit fullscreen mode

Alt Text

Renaming the Existing Remote
Another available option is to simply rename the existing remote and then add the new remote. We can use the remote rename command to rename existing remotes.

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

Enter fullscreen mode

Exit fullscreen mode

For example, we can rename the existing “origin” remote to “origin-old” as shown below.

git remote rename origin origin-old

Enter fullscreen mode

Exit fullscreen mode

Alt Text

Then we can add a new remote with the same name, which is “origin” in this instance. However, it is important to note that this method will create multiple remotes in the repository, and the user is responsible for managing these remotes. We can verify the existing remotes by running the remote -v command.

git remote -v

Enter fullscreen mode

Exit fullscreen mode

Alt Text

Conclusion

In reality, fatal: remote origin already exists error is not a fatal error yet a simple notification informing users that a remote with the same name is already configured in the git repository. Users can easily fix this error using the methods mentioned above. However, the best practice for completely mitigating such errors is to adhere to a proper git workflow in the SDLC.

Понравилась статья? Поделить с друзьями:
  • Renault megane ошибка braking fault
  • Remote host terminated the handshake ошибка
  • Renault megane коды ошибок
  • Remote forkplayer ошибка
  • Remote access 20063 ошибка