Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deleted branch in Gerrit and it is still there, in its Git repo

I started using (was forced to) Gerrit, when my project was already in progress, so I pushed "everything" to Gerrit, using git push orgin -all. Some time ago, I noticed that I also pushed some additional branch, merged into master before starting to play with Gerrit and already locally removed:

$ git branch --all
* master
  remotes/oberon/master
  remotes/origin/96-fix-key-editors-references
  remotes/origin/master

I tried to delete that remote branch, the ususal way (git push origin :remotes/origin/96-fix-key-editors-references), but I was refused by Gerrit, claiming that I don't have Push privilege with Force Push option, which is required to complete this task.

So, I went to Project > Branches in Gerrit's web UI, marked that branch and was able to delete it, by pushing Delete button (interesting: I can do something in UI, what I'm prohibited via SSH?).

I thought case is over, until I again executed git branch --all, only to find out, that Git still reports branch remotes/origin/96-fix-key-editors-references as existing (result exactly like above).

I again used git push origin :remotes/origin/96-fix-key-editors-references, just to feed my curiosity, what will happen now, and I got error message saying error: unable to delete '96-fix-key-editors-references': remote ref does not exist.

So, two questions, but actually one:

  1. How can Gerrit remove branch from web UI, not removing it from Git's repo in the same time?

  2. How can remote branch be listed on list and be undeleteable (as not existing) in the same time?

I'm new to Git and even newer to Gerrit, to I might be missing something obvsious. Sorry for that!

like image 243
trejder Avatar asked Dec 01 '22 17:12

trejder


2 Answers

The branch name that you're seeing in the output from git branch --all is a remote tracking branch; it's a special, read-only branch in your local repository that's synchronized with a branch from a remote each time you fetch. By default, git won't delete them even if the branch is gone from the remote, to give you a chance to recover if you didn't really mean to delete them.

This command will get rid of any stale remote tracking branches that no longer exist in the remote:

git fetch origin --prune
like image 88
Ash Wilson Avatar answered Dec 11 '22 12:12

Ash Wilson


If Gerrit claim that you need Push privilege with Force Push option then you can easily give it from gerrit. just go to Projects > Access then Edit. please see the screen shot for details. Gerrit home page

like image 41
Sharif Avatar answered Dec 11 '22 12:12

Sharif