1

we are using Bitbucket server as remote git server (running in our own datacenter). We went through a merge process via the bitbucket web interface. After the merge the branch is not visible in the Bitbucket web interface any longer.

However it still shows as remote branch on my local repository.

[me@local]$ git branch -r | grep RZAO-140-schreibweise-variable
  origin/feature/RZAO-140-schreibweise-variable

'ok', I am thinking, 'maybe I need to remove it still somehow'

[me@local]$ git push origin --delete feature/RZAO-140-schreibweise-variable
error: unable to delete 'feature/RZAO-140-schreibweise-variable': remote ref does not exist
error: failed to push some refs to 'https://devtools/bitbucket/scm/ina/automation_postgres.git'

I tried git push origin :branch-name as an alternative with the same result. The eroor itself makes complete sense ... that branch is not existing on the remote any longer, so I guess I need to clean up the local brain of git, so it does stop to think there was a remote branch of that name.

just .... how to I achieve that?

vrms
  • 217
  • 2
  • 8

1 Answers1

1

The branches shown by git branch -r are "remote-tracking branches": branches in your local repository which track the state of a particular branch on another repository when you run git fetch or related commands.

When you fetch from a remote, git defaults to creating and updating these branches, but not deleting them. The manual for git fetch justifies this as so:

Git has a default disposition of keeping data unless it’s explicitly thrown away; this extends to holding onto local references to branches on remotes that have themselves deleted those branches.

It then goes on to list two main ways to "prune" them:

  • With git fetch --prune
  • With the config option fetch.prune, to set that flag on by default

You can also perform the prune without fetching new / updated branches with the command git remote prune.

Note that you may also have a local branch called RZAO-140-schreibweise-variable, which will not be "pruned" by the above commands. For that, see this previous question: "Remove tracking branches no longer on remote".

IMSoP
  • 89,526
  • 13
  • 117
  • 169