Search code examples
gitgithubbranchgit-pushgit-fork

Delete branches which are not in the local repository using git


There's a bunch of branches on one of my git repo's that I got when I forked it on GitHub. I don't want my GitHub fork to have these branches.

Is there any way that I can delete all the branches on my GitHub repo that are not in my local repo?


Solution

  • git push --mirror <origin> will make the refs on the remote match those in the local repository, including deleting branches that you don't have locally.

    From git help push:

    --mirror
        Instead of naming each ref to push, specifies that all refs under
        refs/ (which includes but is not limited to refs/heads/,
        refs/remotes/, and refs/tags/) be mirrored to the remote
        repository. Newly created local refs will be pushed to the remote
        end, locally updated refs will be force updated on the remote end,
        and deleted refs will be removed from the remote end. This is the
        default if the configuration option remote.<remote>.mirror is set.