Top community members
All Wiki Articles Create Wiki Article

Welcome to Dirask IT community! ❤ 💻
We are community of people that helps each other.

If you think you have some skills to help others

help someone and become a part of our community - List Q & A

Git reset hard with untracked files removal

0 contributions
5 points

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

git reset --hard HEAD && git clean -fd

This cmd will reset our branch and remove all untracked files and directories.
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:

2. Explanation of git reset --hard HEAD

$ git reset --hard HEAD

Git will leave untracked files.

3. Explanation of git clean -fd

git clean most useful flags:

-n, --dry-run         dry run
-f, --force           force
-d                    remove whole directories

git clean -help entire output:

$ git clean -help
usage: git clean [-d] [-f] [-i] [-n] [-q] [-e <pattern>] [-x | -X] [--] <paths>...

    -q, --quiet           do not print names of files removed
    -n, --dry-run         dry run
    -f, --force           force
    -i, --interactive     interactive cleaning
    -d                    remove whole directories
    -e, --exclude <pattern>
                          add <pattern> to ignore rules
    -x                    remove ignored files, too
    -X                    remove only ignored files

4. Explanation of git clean --dry-run

$ git clean --dry-run

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

5. References

  1. git reset - Docs
  2. git clean - Docs
0 contributions

Checkout latest Findings & News:

Checkout latest questions:

Checkout latest wiki articles:

Hey 👋
Would you like to know what we do?
  • Dirask is IT community, where we share coding knowledge and help each other to solve coding problems.
  • We welcome everyone,
    no matter what the experience,
    no matter how basic the question is,
    this community will help you.
Read more