0

Is there a way to remove the local branch which is merged and deleted on remote with main/master?

I follow these steps while working with git -

  1. Create a local branch
  2. Raise PR
  3. PR gets merged and the branch is deleted from the remote too
  4. On local - I switch to master and take a pull

Now the branch is not on remote but it is still on my local. I want to know how other people manage this, do they delete local branches manually every time or is there any other way that I am missing?

Randommm
  • 410
  • 1
  • 9
  • It has to be done on your local.... you could _script_ it so that you could delete local branches that are already merged into a given branch (as long as they were _really_ merged, not rebased or squashed). check `git help branch`, specifically `--merged`. – eftshift0 May 03 '23 at 13:36
  • Does this answer your question? [How do I delete all Git branches which have been merged?](https://stackoverflow.com/questions/6127328/how-do-i-delete-all-git-branches-which-have-been-merged) – Fantastic Mr Fox May 03 '23 at 14:06
  • How many local branches are you creating that occasional manual cleanup is a challenge? I keep branches grouped (in virtual folders with slash notation) by month or project. Occasionally I clean them up manually. I don't have a real need for automatic housekeeping (nor would I necessarily trust that such a mechanism wouldn't be overly aggressive). – isherwood May 03 '23 at 14:06
  • Follow the instructions in [this question](https://stackoverflow.com/questions/6127328/how-do-i-delete-all-git-branches-which-have-been-merged) (already linked) and then make cron job or something else to schedule a fetch + delete (depends on your OS). – Guildenstern May 03 '23 at 14:13

0 Answers0