git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: git branch doesn't allow me to forcibly delete branch which was checked out in a now-deleted worktree dir

From
Erik Johnson <palehose@gmail.com>
Date
Jul 9, 2016, 05:05 UTC
Message-ID
<20160709050500.GD1916@gmail.com>
In-Reply-To
<CA+P7+xoLKmUaJ9f1obVVDyjBTBe=XvSACvL8uiJWYf+2MTMN8w@mail.gmail.com>
On Fri, Jul 08, 2016 at 09:58:26PM -0700, Jacob Keller wrote:
Show 25 quoted lines
>On Fri, Jul 8, 2016 at 7:22 PM, Erik Johnson <palehose@gmail.com> wrote:
>> On Fri, Jul 08, 2016 at 05:41:17PM -0700, Jacob Keller wrote:
>>> It is possible we should update "git branch -d" should perform a
>>> worktree prune first, since that would enable it to determine that you
>>> deleted the directory, and any worktree which is removable should be
>>> marked as persistent.
>>>
>>> Given that there is a known workaround (git worktree prune) and that
>>> it is expected behavior for a branch checked out to prevent deletion,
>>> I think the best coarse of action would be to patch git branch -d to
>>> do a prune before attempting to delete.
>>>
>>> Thanks,
>>> Jake
>>
>>
>> Well, I never mentioned -d (I was using -D), but I think we're both in
>> agreement.
>>
>>
>
>Out of curiosity, what is git branch -D behavior when the worktree does exist?
>
>Thanks,
>Jake
It works the same irrespective of whether or not the directory exists:

% git worktree add ../foo Preparing ../foo (identifier foo) HEAD is now at 91e095b Merge pull request #34429 from terminalmage/pkg-latest-versioncheck % git branch -D foo error: Cannot delete branch 'foo' checked out at '/home/erik/git/salt/foo' % rm -rf /home/erik/git/salt/foo % git branch -D foo error: Cannot delete branch 'foo' checked out at '/home/erik/git/salt/foo' % git worktree prune -v Removing worktrees/foo: gitdir file points to non-existent location % git branch -D foo Deleted branch foo (was 91e095b).

--
-Erik

"For me, it is far better to grasp the universe as it really is than to persist in delusion, however satisfying and reassuring." --Carl Sagan

Previous: Jacob KellerNext: Duy Nguyen
Message 7 of 8 in “git branch doesn't allow me to forcibly delete branch which was checked out in a now-deleted worktree dir”
  1. Erik JohnsonJul 7, 2016
  2. Jacob KellerJul 7, 2016
  3. Erik JohnsonJul 8, 2016
  4. Jacob KellerJul 9, 2016
  5. Erik JohnsonJul 9, 2016
  6. Jacob KellerJul 9, 2016
  7. Erik JohnsonJul 9, 2016
  8. Duy NguyenJul 9, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.