# TIL: Using git restore to Revert File Changes and Sync with Another Branch


> **Today I learned** that if you need to revert a specific file to its original
state, even after commits, or if you want to sync a file with another branch,
you can use the `git restore` command.

The `git restore` command allows you to revert a file to its previous state or sync it with a different branch. This can be particularly useful when you need to discard changes and align a file with its version from another branch, such as main. 

In this example, I want to restore and discard all committed changes in my current branch for a specific file to match the version from the main branch:

```bash
git restore --source=main -- main.tf
```

* git-restore [documentation](https://git-scm.com/docs/git-restore)
* Cover image is licensed with [ Creative Commons Attribution 3.0
  Unported](https://creativecommons.org/licenses/by/3.0/deed.en)
  and [source](https://commons.wikimedia.org/wiki/File:Git-logo.svg)
  
