Completely reset a local Git branch

Git

Your local branch is broken and you want a clean copy from origin.

  1. Fetch latest refs

    git fetch origin
  2. Switch to branch

    git checkout <branch>
  3. Hard reset to remote

    git reset --hard origin/<branch>
    Destructive
  4. Remove untracked files

    git clean -fd
    Destructive

Notes

  • Stash or back up local work before destructive commands.
  • Use --dry-run with git clean first when unsure.

Related commands: git fetch --prune, git reset --hard, git clean -fd

Related workflows: Undo last commit, Compare branches