Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git: says origin already exists on "NEW" (init) repository, using shell but installed Github for Windows

I installed Git for Windows, although I am using the shell not the Windows interface.

If I do a git init, and then try and do a

 git remote add origin [email protected]:someuser/testme.git

I get the following error

 fatal: remote origin already exists.

So I do a

 git remote -v

and it returns the following

origin
upstream

So it appears its there but has no URL set, I don't understand why it's there?

If I do a

 git remote rm origin

it produces this

 error: Could not remove config section 'remote.origin'

It says that it can't remove the remote.origin config section; I checked the .gitconfig under my home directory and I don't see anything.

Anyway I was able to remedy this by using

 git remote set-url origin [email protected]:someuser/testme.git

But I am getting confused as I have used Git before and this never happened.

Could this be something to do with Git for Windows?

like image 412
Martin Avatar asked Jun 09 '13 17:06

Martin


People also ask

What does remote origin already exists mean?

"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.


3 Answers

I'm the developer who put this in. Here's why I added this to the system gitconfig, it's pretty useful!

## Because of this change, git fetch knows about PRs
git fetch

## Now, I can merge PRs by number
git merge origin/pr/24

## See changes from PR #53
git diff master...origin/pr/53

## Get the commit log from PR #25
git log origin/pr/25

Unfortunately, this does have the consequence that the origin remote always exists, even when it doesn't.

Workaround

Whenever you see git remote add origin https://..., instead:

git remote set-url origin https://...
like image 125
Ana Betts Avatar answered Sep 18 '22 01:09

Ana Betts


I've been running into the same issue, and I think I've figured it out finally. GitHub for windows installs a version of PortableGit in /Users/<username>/AppData/GitHub. In the PortableGit directory, under /etc, there's a gitconfig file. This is the system config. It defines "origin" and "upstream", presumably with defaults that are meaningful to GitHub.

I can't say for sure, but I started noticing this problem in the latest few updates of the GitHub for Windows client. Sadly, the release notes don't point to anything probative and the Windows client isn't open-source so it's hard to tell.

I've sent a message to their support address, so I'll update here if I hear anything back.

Edit: GitHub support responded saying this is a known issue and will be fixed soon.

like image 29
Chad Avatar answered Sep 19 '22 01:09

Chad


I simply deleted the origin section in %appdata%/Local/GitHub/PortableGit_.../etc/gitconfig and everything went back to normal - new repos act accordingly when I add remote origin to them, since they have none when they are created.

There might be side effects for this deletion, but so far I haven't ran into any trouble.

like image 43
Yaniv Kessler Avatar answered Sep 19 '22 01:09

Yaniv Kessler