0

While trying different branches, merging them and deleting them, the delete part still confuses me. I work with VS Code and I created a repository on GitHub. Creating new branches works totally fine and I understood the push and commit commands. But as soon I have merged my branch (name: branch2) to the main branch I can not find an easy way for deleting the not used branch2 local and remote.

What I have tried:

  1. Delete branch in GitHub: With git pull --prune I could achieve that my branch2 is not shown in GitHub and also the origin/branch2 in VS Code is gone. But my local saved branch2 in VS Code is still visible.

  2. Delete branch in VS Code either with the command or in the source control section. With this I can delete my local branch 2, but it will not delete the origin/branch2 in GitHub.

I am sure there is a way to delete the local branch and the remote origin branch in GitHub, but I could not find it yet.

Mehdi Charife
  • 722
  • 1
  • 7
  • 22
Mawela
  • 11
  • 1
  • *I am sure there is a way to delete the local branch and the remote origin branch in GitHub* Why? These are two distinct operations, and although outer tools could somehow automate the two, in git you can't do both at once like an atomic action. – Romain Valeri Aug 30 '23 at 14:21
  • What do you mean by the same time? Are you looking for something like a single command or button click? Running `git branch -d && git push origin --delete ` could delete both local and remote branches, but I don't know if it satisfies what you mean by *"the same time"* – Mehdi Charife Aug 30 '23 at 14:22
  • What I am aiming for is a way I do not have to delete a branch singlehanded in vscode and in github. But reading your comments I guess that is actually not possible. But is there a way to delete branches in vscode that have been deleted in github, when i do not remember anymore which branch it is. Kind of a delete the remote deleted branches? Henriks answer with git remote prune origin did not change anything for me but i also dont really understand what it does still have to do my research – Mawela Aug 30 '23 at 19:37
  • @Mawela Reading your last comment, does [this](https://stackoverflow.com/a/7727380/15312420) answer you question? – Mehdi Charife Aug 30 '23 at 21:24
  • 1
    @MehdiCharife thanks! It sounds like what I am searching for. I will look into it. – Mawela Aug 31 '23 at 07:13

1 Answers1

0

With the command git remote prune origin you can delete local branches that no longer exist remotely. Same can be achieved with git fetch --prune (or git fetch -p)

henrik
  • 1,558
  • 3
  • 14
  • 29