Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deleting branch with repo abandon and git branch -D

Tags:

git

git-repo

I am using git and git-repo for my project. I see when I try to delete my local branch which I am currently on using git command

git branch -D branch_name

It shows me error which I am expecting, as we can't delete current branch.

But if I use repo command

repo abandon branch_name

I am able to delete the current branch. So my question is what command is repo using internally to delete the branch?

like image 819
mrutyunjay Avatar asked May 23 '13 05:05

mrutyunjay


1 Answers

The abandon.py subcmd calls project.AbandonBranch, which includes:

head = self.work_git.GetHead()
if head == rev:
  # We can't destroy the branch while we are sitting
  # on it.  Switch to a detached HEAD.
  #
  head = all_refs[head]

  revid = self.GetRevisionId(all_refs)
  if head == revid:
    _lwrite(os.path.join(self.worktree, '.git', HEAD),
            '%s\n' % revid)
  else:
    self._Checkout(revid, quiet=True)

In other words, it makes sure to not be on the branch you are deleting, even if that mean setting up a detached HEAD (by a checkout of a SHA1 'revid').

like image 170
VonC Avatar answered Sep 30 '22 14:09

VonC