seachicken / gh-poi

✨ Safely clean up your local branches
https://dev.to/seachicken/safely-clean-up-your-local-branches-9i3
MIT License
673 stars 19 forks source link

Delete the tracking branch as well. #67

Closed OkazakiTokkatsu closed 2 years ago

OkazakiTokkatsu commented 2 years ago

Description

I would like the tracking branch (remotes/origin/****) removed at the same time.

Steps to reproduce

  1. Ensure that the merged branch remains.

    $ git branch -a
    
      some-topic-branch
    * main
      remotes/origin/some-topic-branch
      remotes/origin/HEAD -> origin/main
      remotes/origin/main
  2. Run gh-poi

    $ gh-poi
    
    ✔ Fetching pull requests...
    ✔ Deleting branches...
    
    Deleted branches
      Some-topic-branch
        └─ #1  https://github.com/Okako-WebWorks/TicketSystem/pull/***
    
    Not deleted branches
    * main
  3. Ensure that the tracking branch remains in place.

    $ git branch -a
    
    * main
      remotes/origin/some-topic-branch
      remotes/origin/HEAD -> origin/main
      remotes/origin/main
  4. Run prune

    $ git fetch --prune
    
     - [deleted]         (none)     -> origin/some-topic-branch
  5. Now, all branches was cleaned!

    $ git branch -a
    
    * main
      remotes/origin/HEAD -> origin/main
      remotes/origin/main

Perhaps the prune executed here should be done by gh-poi. (The above command may not be sufficient to avoid gh-poi deleting tracking branches other than the one you deleted.)

Additional context

gh version 2.14.3 (2022-07-26) gh poi seachicken/gh-poi v0.5.6

seachicken commented 2 years ago

Thanks for giving me a good feature request. I will check a little more to see if this change has any negative impact.

seachicken commented 2 years ago

I thought pruning was also good for the purpose of this tool to clean up.

I would proceed with the following policy: With --dry-run: Do not pruning Without --dry-run: git remote prune after removing branches (git fetch --prune includes getting remote-tracking branches, so we will proceed without fetch)