↑ ↓ select, Enter open, Esc close

Hard reset a working copy to the remote branch

Adjust the values, the command updates live
user@server
git fetch origin && git reset --hard origin/main

Fetches the current state from the remote origin and sets the current branch, the index and all tracked files exactly to it. Typically used on deployment servers when git pull fails because of local changes or diverging history. Untracked files such as uploads remain untouched.

Note: Local uncommitted changes are lost afterwards. Discarded local commits can still be rescued for a while via git reflog.

Also searched as

  • git reset local branch to origin
  • git pull fails because of local changes
  • discard all local changes git
  • your branch has diverged

Related one-liners

All in Git

Read first, then run.

The commands on myline.de act directly on servers, files and databases. A wrong path or placeholder can delete data irreversibly or make a server unreachable.

  • All commands are provided without warranty and are not tested on every system.
  • Understand what a command does before running it, and check every placeholder.
  • Make a backup first and, if possible, try it on a test system.
  • You run commands at your own risk. Liability for damages is excluded to the extent permitted by law.