Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git clean is not cleaning untracked files

Tags:

git

git-clean

I'm getting the "The following untracked working tree files would be overwritten by checkout...please move or remove them before you switch branches" error.

The common fix appears to be git clean

When I type that in, I get no error, but nothing happens. And when I go to check out another branch, I just get the same error as above.

Any reason as to why git clean would do absolutely nothing?

UPDATE:

More info. git -n and git -f do exactly the same...nothing.

like image 710
DA. Avatar asked Aug 15 '18 21:08

DA.


Video Answer


1 Answers

If you want to clean untracked files, use the below command. But, take care before running this, as it will wipe your working area, index, HEAD.

git reset --hard

I think you are having untracked directories or ignored files(build files) of gitignore in your working area. you can remove them by the below command.

git clean -dfx

-d

Remove untracked directories in addition to untracked files. If an untracked directory is managed by a different Git repository, it is not removed by default. Use -f option twice if you really want to remove such a directory.

-f --force

If the Git configuration variable clean.requireForce is not set to false, git clean will refuse to delete files or directories unless given -f, -n or -i. Git will refuse to delete directories with .git sub directory or file unless a second -f is given.

-x

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.

For more information git clean

like image 88
Venkataraman R Avatar answered Nov 10 '22 00:11

Venkataraman R