I want to reset a file stored in a git repo to its state as the main branch, and I kept forgetting how to do this.

So here is how, just to remind my future self.

➜ git status
On branch main
Your branch is up to date with 'origin/main'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   kube-prometheus-stack-values.yaml

no changes added to commit (use "git add" and/or "git commit -a")

The above output shows that there is a modified file, kube-prometheus-stack-values.yaml that is not yet staged for commit.

Let’s revert it back to its state in main:

➜ git checkout main -- kube-prometheus-stack-values.yaml

➜ git status
On branch main
Your branch is up to date with 'origin/main'.

nothing to commit, working tree clean

Reference: