github fatal: remote origin already exists.

What does this error mean??

I was working on a project, I followed the necessary steps from Github

1. Create a new repo

2. In the app terminal, git innit

3. git remote add origin git@github.com:username/projectname

4. git remote -v //to verify the origin

5. git add .

6. git commit -m “first commit”

7. git push

And that’s when I got this error.

“github fatal: remote origin already exists.”

For the life of me, I don’t know how I got the error.

After googling, I found a simple fix for this.

In the app terminal, type in:

git remote rm origin

Then type in the command git remote add origin URL

git remote add origin git@github.com:username/projectname

Doing these two steps resolved the issue.

Now, let’s see what “github fatal: remote origin already exists” actually means.

From the GitHub Docs (https://docs.github.com/en) on Manage Remote Repositories , this is what it states:

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

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.

o 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

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)

· Delete the existing remote repository before you add the new remote. For more information, see “Removing a remote repository” (https://docs.github.com/en/get-started/getting-started-with-git/managing-remote-repositories#removing-a-remote-repository) below. “

o 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

Example

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.

I’m so glad to know there was an easy fix to this.

I’m definitely thankful for the GitHub Docs that helped resolve this issue.

Hello, I am a young enthusiastic Software Engineer. Looking forward to an opportunity to use my skills for mutual benefits and growth as well.