You have several ways to do what you want.
Detailed answer can be found here: How to move HEAD back to a previous location? (Detached head)
Another option which is not there and is suitable answer for your question is git clean.
git clean
You can do a git clean to remove all the un-tracked files (Backup files)
git clean -Xfd // capital X
git clean -xfd // small x
-x (lower case)
Don’t use the standard ignore rules read from .gitignore
(per directory) and $GIT_DIR/info/exclude
, but do still use the ignore rules given with -e options.
This allows removing all untracked files, including build products.
This can be used (possibly in conjunction with git reset) to create a pristine working directory to test a clean build.
-X (uppercase)
Remove only files ignored by Git.
This may be useful to rebuild everything from scratch, but keep manually created files.