gitmeld

stale remote branches are not cleaned from upstream references


When invoking meld inside a git repo, I get a bunch of warnings before meld opens :

# from within a git repo :
$ meld .
fatal: bad revision '^origin/branch/one'
fatal: bad revision '^origin/branch/two'
fatal: bad revision '^origin/branch/three'
...

This is just a warning printed on STDERR, meld runs fine afterwards and displays the expected diff.

Most of these branches have a local checkout, but no matching remote reference on origin.
One of these references doesn't even exist locally (it is one misspell away from an existing branch).

Does someone know I could dispose of these disgraceful messages ?


Solution

  • The problem was in my repo configuration.

    Some local branches were still tracking stale remote branches :
    the .git/config file still contained sections :

    [branch "branch/one"]
        remote = origin
        merge = refs/heads/branch/one
    

    even though the remote branch branch/one did not exist anymore, and my local reference origin/branch/one was (correctly) deleted.

    I didn't find any direct command to clean my local branches up.
    I was hoping git remote prune origin would clean this up, but it didn't.

    Here is a way I found to have my local branches stop tracking stale remote branches :

    # enumerate all local branches, and print "branchname upstreamname" :
    git for-each-ref --format="%(refname:short) %(upstream:short)" refs/heads |\
    
    # keep branches which track a remotre branch in origin :
    grep "origin/" |\
    
    # loop on output :
    while read local remote; do
      # use any command which fails on an invalid ref :    
      if ! git show $remote -- &> /dev/null then
        # if it failed : stop tracking this stale remote
        git branch $local --unset-upstream
      fi
    done