How do I reset the state of a branch in a local Git repository to that of a remote branch?
There are two commands you can use to achieve this. First, download all remote branches with
git fetch origin # <-- name of remote, change if not origin
git reset to sync the local branch with the remote branch:
git reset --hard origin/main
This process will destroy any uncommitted work, as well as any unpushed commits, so caution is advised. Consider making a backup of the local state on a separate branch, before running
git commit -a -m "Backup of local work" git branch local-work