Search code examples
windowsgitversion-controltortoisegitgit-for-windows

How to reset the entire Git repository, and not only the "Master" branch, to match Remote?


What the title says.

I want to reset each and every local branch to match my Remote repository, including deleting some branches and tags which only exists locally, without having to delete everything and cloning from scratch. All I could find are instructions on how to reset a specific branch, but not the entire repository.

Even better if it can be done from the TortoiseGit Shell extension. But I'm also fine with the command line.


Solution

  • You can do it by following commands:

    git checkout --orphan @
    git fetch <Remote> refs/*:refs/* --refmap= --prune --force
    

    where <Remote> is remote repository you want to use. You simply fetch all remote refs (refs/*:refs/*) with --prune and --force flags to remove and force update local references.