Languages
[Edit]
EN

Git reset hard with untracked files removal

5 points
Created by:
Root-ssh
178290

1. Git reset hard and remove all untracked files and directories

Edit
  • This cmd will reset our branch and remove all untracked files and directories (non-ignored by .gitignore).
  • All uncommited changes will be removed and we have clean state on the branch.
  • Very powerful command, before using it think twice.

 

Practical example on some temporary files:

Git reset hard and remove all untracked files and directories
Git reset hard and remove all untracked files and directories

If we want to remove all files and directories (even ignored by .gitignore - it will also remove all IDE configurations if stored under project), below command can do the trick:

2. Explanation of git reset --hard HEAD

Edit

Git will leave untracked files.

3. Explanation of git clean -fd

Edit

git clean most useful flags:


git clean -help entire output:

4. Explanation of git clean --dry-run

Edit

This command will list what will be deleted.
It is useful to run it before running git clean -fd.

5. References

Edit
  1. git reset - Docs
  2. git clean - Docs

Alternative titles

  1. git reset hard untracked files
  2. git reset hard still shows untracked files - how to solve it and reset all
  3. git reset hard dirask
  4. git reset hard all files
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

Git

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join