0

I was following this steps to succesfully manage 2 environments in Heroku, and how to set that up in git. Everything worked fine, but now I've got a problem with git showing me old name of a remote, and can't delete it.

Before the tutorial, I had only two remotes, origin and heroku. But as stated, recommended convention names are staging and production, so I renamed the remote heroku to staging via the .git/config file. In that change, I had to follow this instructions: "Cannot update paths and switch to branch at the same time" because the renamed staging remote wouldn't show any branches. The fetch made the trick.

Push/pulls and deploys are working very nice now with both Heroku envs, but Sourcetree and git console are showing the old remote name, and I can't get rid of it:

> git branch -avv
* develop                 [origin/develop] Merge branch 'dummy-fix' into develop
dummy-fix                 changed full vs first_name
master                    [origin/master] Merge branch 'develop'  
staging                   [staging/master] Merge branch 'develop' into staging
remotes/heroku/master     Merge branch 'develop'
remotes/origin/develop    Merge branch 'dummy-fix' into develop
remotes/origin/master     Merge branch 'develop'
remotes/production/master Merge branch 'develop'
remotes/staging/master    Merge branch 'develop' into staging

The remote remotes/heroku/master shouln't exist, but when I do:

> git remote rm heroku
error: Could not remove config section 'remote.heroku'

This is my .git/config (clearly not the real URLs):

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
    ignorecase = true
    precomposeunicode = true
[remote "origin"]
    url = https://my-user@the-repo-url-in-bitbucket.git
    fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
    remote = origin
    merge = refs/heads/master
[branch "develop"]
    remote = origin
    merge = refs/heads/develop
[remote "staging"]
    url = https://git.heroku.com/my-app-name-in-staging.git
    fetch = +refs/heads/*:refs/remotes/staging/*
[remote "production"]
    url = https://git.heroku.com/my-app-name-in-production.git
    fetch = +refs/heads/*:refs/remotes/production/*
[heroku]
    remote = staging
[push]
    default = tracking
[branch "staging"]
    remote = staging
    merge = refs/heads/master
Community
  • 1
  • 1
unmultimedio
  • 1,224
  • 2
  • 13
  • 39
  • `remotes/heroku/master` is not a remote, it's a *remote-tracking branch*. These are (mostly) separate concepts (though it makes little sense to have a remote-tracking branch that has no corresponding remote). The *remote* is just a simple name (like `origin` or `production`) and the *remote-tracking branch* is a reference whose full name starts with `refs/remotes/`, followed by a remote name, followed by a branch name. – torek Nov 26 '16 at 20:36

1 Answers1

1

I kept digging, seems to be that .git folder has more references to remotes that just in the config file. Found 3 spots where I got rid manually of the folder heroku, or the ref in config file, and that seems to fix it. Now I don't see the ghost remote neither in terminal nor Sourcetree.

enter image description here

unmultimedio
  • 1,224
  • 2
  • 13
  • 39
  • 1
    Normally, deleting a remote should delete all the corresponding remote-tracking branches (see my other comment on the question). If that has failed for some reason, though, you can use `git branch -r -d` to delete remote-tracking branches from the command line. – torek Nov 26 '16 at 20:44
  • Very useful that line. Thanks @torek – unmultimedio Nov 26 '16 at 20:46
  • In my case, I just remove all the branches in /.git/refs/remotes/, and use SourceTree to update remote repositories. After this my ghost repo are all gone. RIP. – laishiekai Nov 13 '17 at 19:39