Siavash
Siavash

Reputation: 7853

Git says origin already exists, when it REALLY doesn't

I am trying to set up git, I am starting with everything fresh, and I've following all the steps in https://help.github.com/articles/create-a-repo (except instead of creating a readme file, I did git init in my source code project folder and did 'git add *.*') but heres what happens when I try to add roigin:

E:\eclypse\workspace [master]> git remote add origin https://github.com/my-repo/android-projects.git
fatal: remote origin already exists.
E:\eclypse\workspace [master +0 ~7 -0]> git remote -v
origin
upstream
E:\eclypse\workspace [master +0 ~7 -0]> git remote rm origin
error: Could not remove config section 'remote.origin'

I know the remote DOES NOT already exist, here is my config file:

[core]
repositoryformatversion = 0
filemode = false
bare = false
logallrefupdates = true
symlinks = false
ignorecase = true
hideDotFiles = dotGitOnly

Whats going on? NOTE: I know I can just use another name besides 'origin' but there is something wrong here and I want to figure out what. And I did try using a different name for origin, I run into issues later down the line.

update, here are the contents of my .gitconfig file

[user]
name = Siavash Bonakdar
email = [email protected]

Upvotes: 2

Views: 5650

Answers (2)

Matthieu Moy
Matthieu Moy

Reputation: 16517

A remote corresponds to two things:

  • A piece of configuration in .git/config

  • A set of refs, in the namespace refs/remotes/$remote

I believe you have the second, but not the first (most likely because you removed the remote from your .git/config file earlier).

git remote rm tries to remove both, but the fact that the refs should be stored in refs/remotes/$remote is stored in the configuration file, and this information does not exist anymore, hence git cannot remove these refs.

You can either re-create manually the remote section in the config file to allow git remote rm to run properly, or use git update-ref -d on each ref to delete (use git for-each-ref to find out which).

Upvotes: 0

michas
michas

Reputation: 26515

Information about known remotes are just stored as a normal git configuration.

git stores its configuration in (potentially) three different places. For system wide configuration, personal configuration and repository specific configuration.

You can list all the different configuration:

git config --list --system
git config --list --global
git config --list --local

One of those places should list something about remote.origin.*.

You can edit the corresponding file using one of these:

git config --edit --system
git config --edit --global
git config --edit --local

Upvotes: 3

Related Questions