# How to undo commits in Git (locally and on GitHub) and recover “lost” files with reflog

It happens to everyone: you make a commit, push it to GitHub, realize something shouldn’t be there… and while trying to fix it you end up “losing” a file or a commit.

Good news: **Git almost always has a way out** (especially if you use `reflog`).

In this post you’ll learn:

- How to **undo the last commits** locally and on GitHub