Removing a branch with rollback repo and git branch -D

I am using git and git-repo for my project. I see when I try to remove the local branch in which I am now using the git command

git branch -D branch_name 

It shows me the error that I am expecting, since we cannot delete the current branch.

But if I use the repo command

 repo abandon branch_name 

I can delete the current branch. So my question is, which repo command does it use internally to delete a branch?

+4
source share
1 answer

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 should not be on the branch you are deleting, even if it means setting up the remote HEAD (by checking SHA1 revid ').

+3
source

Source: https://habr.com/ru/post/1482308/


All Articles