How to remove git working tree branch when deleting working directory?

I deleted my working directory because this git working tree is no longer useful, and then I git branch -D pubsub-sketch-tree in the main repository directory. Error:

 error: Cannot delete branch 'pubsub-sketch-tree' checked out at '/Users/zhouhancheng/编程/github_own/sketch_worktree/pubsub-sketch_tree' 

But '/ Users / zhouhancheng / 编程 / github_own / sketch_worktree / pubsub-sketch_tree' were deleted.

+2
source share
2 answers

You are using git worktree , so the answer is in the git worktree documentation :

When you are done with the linked work tree, you can simply delete it. Administrative files of working trees in the repository (see "DETAILS" below) will be automatically deleted (see gc.worktreePruneExpire in git -config (1) ) or you can run git worktree prune in the main or any linked working tree to clear all obsolete ones administrative files.

(my emphasis). Git will not allow you to delete a branch if it believes that it has been checked out in a secondary workgroup. If the secondary working line has already been deleted, but Git has not yet caught this fact, simply run git worktree prune to tell Git to check the progress.

+4
source

I deleted his working directory

You will have an easier time with Git 2.17+ (Q2 2018), since " git worktree " recognized the move and remove subcommands. "

See commit 7f19def (March 04, 2018) by Eric Sunshineco .
See commit ee6763a , commit cc73385 , commit 78d986b , commit c64a8d2 , commit 9f792bb , commit 9c620fc (February 12, 2018) and commit 4ddddc1 (January 24, 2018) Nguyễn Thái Ngọc Duy ( pclouds ) .
(merged Junio ​​C Hamano - gitster - in commit bd0f794 , March 14, 2018)

worktree remove : new team

This command allows you to delete the working line. Like "move", you cannot delete the main operating line or one with submodules inside.

To delete $GIT_WORK_TREE , files without tracking or any phased entries are considered precious and therefore prevent deletion by default. Ignored files are not valuable.


worktree remove: allow when $GIT_WORK_TREE already gone

" git worktree remove " consists mainly of two things

  • remove $GIT_WORK_TREE
  • remove $GIT_DIR (which is $SUPER_GIT_DIR/worktrees/something )

If $GIT_WORK_TREE already $GIT_WORK_TREE for some reason, we must be able to complete the task by deleting $GIT_DIR .

0
source

All Articles