Bash

Reset Branch to Match Remote

admin by @admin ADMIN
6m ago
May 31, 2026
Public
0 0 up · 0 down Sign in to vote
Throw away local commits and resync to origin. Destructive — make sure no local work is at risk first.
Bash
Raw
# Soft check: how far ahead/behind are we?
git fetch origin
git status -sb
# ## main...origin/main [ahead 3, behind 2]

# Discard local commits, reset to origin/main exactly
git fetch origin
git reset --hard origin/main

# Also wipe untracked files (DANGEROUS — review first)
git clean -fdx -n               # -n = dry run, shows what WOULD be removed
git clean -fdx                  # actually do it

# Nuclear option: reset + clean to a pristine state matching origin
git fetch origin
git reset --hard origin/main
git clean -fdx
Tags

Save your own code snippets

Create a free account and build your private vault. Share publicly whenever you want.