I somehow mucked up a locally hosted repository of mine, not sure how though. If I create a fresh clone of this project and look at my remotes I get the following. Note, GitHandle
is an SSH alias which is working.
For clarity, I'll refer to the repository at GitHandle:/opt/git/www.project2.com.git
as the "correct" one and the repository at GitHandle:/opt/git/www.project1.local.git
as the "incorrect" one.
bash-4.4$ git clone GitHandle:/opt/git/www.project2.com.git htdocs
bash-4.4$ ...
bash-4.4$ cd ./htdocs
bash-4.4$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working tree clean
bash-4.4$ git remote -v
origin GitHandle:/opt/git/www.project1.local.git (fetch)
origin GitHandle:/opt/git/www.project1.local.git (push)
origin GitHandle:/opt/git/www.project2.com.git (push)
bash-4.4$ git branch -a
* master
remotes/origin/HEAD -> origin/master
remotes/origin/develop
remotes/origin/master
bash-4.4$
Somehow, I have the "incorrect" project (www.project1.local) setup as the remote in addition to the "correct" project, but both are configured as origin
. For some reason there isn't a corresponding fetch
for the "correct" project either.
If I check ./.git/config
, it appears origin is configured correctly.
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
[remote "origin"]
url = GitHandle:/opt/git/www.project2.com.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
I then figured I could just remove origin and re-add it with the correct one. The command appears to be successful. It removed the entry from ./.git/config
and removed the "correct" remote. But the "incorrect" one is still hanging around.
bash-4.4$ git remote rm origin
bash-4.4$ git remote -v
origin GitHandle:/opt/git/www.project1.local.git (fetch)
origin GitHandle:/opt/git/www.project1.local.git (push)
bash-4.4$
If I check ./.git/config
, there is no trace of origin
at all.
bash-4.4$ nano ./.git/config
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
[branch "master"]
I decided to attempt to remove origin again, just to see if it appeared to succeed again. This time around, it errors out.
bash-4.4$ git remote -v
origin GitHandle:/opt/git/www.project1.local.git (fetch)
origin GitHandle:/opt/git/www.project1.local.git (push)
bash-4.4$ git remote rm origin
error: Could not remove config section 'remote.origin'
bash-4.4$
If I then try to add the "correct" origin back, it still retains the "incorrect" one and only adds a push
for the "correct" remote.
bash-4.4$ git remote set-url origin GitHandle:/opt/git/www.project2.com.git
bash-4.4$ git remote -v
origin GitHandle:/opt/git/www.project1.local.git (fetch)
origin GitHandle:/opt/git/www.project1.local.git (push)
origin GitHandle:/opt/git/www.project2.com.git (push)
bash-4.4$
If I check my ./.git/config
file, it appears origin is correctly set:
bash-4.4$ nano ./.git/config
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
[branch "master"]
[remote "origin"]
url = GitHandle:/opt/git/www.project2.com.git
I'm having a hard time figuring out what to do next to troubleshoot this. I'm afraid someone is going to push their changes to the wrong project (hopefully no one "forces" it). Can anyone suggest some avenues I could explore to try and figure this out. Any ideas where it's getting the "incorrect" remote?
I have full access to the remote repositories if anything is needed there. Please let me know if I should provide anything additional which may help.
It sounds as if you may have a remote
configured in your global ~/.gitconfig
file. Take a look there and remove it if you find one.