3

I hit this today:

% git checkout another_branch
error: The following untracked working tree files would be overwritten by checkout:
        __version__.txt
        alembic.ini
        alembic/README
        alembic/env.py
        alembic/script.py.mako
        folder1/file1
        folder2/file2
        ....
Please move or remove them before you can switch branches.
Aborting

OK, so I'll remove untracked files:

% git clean -f
Not removing alembic/
Not removing tools/maintenance/

However, it seems that not all untracked files have been removed:

% git checkout another_branch
error: The following untracked working tree files would be overwritten by checkout:
        alembic/README
        alembic/env.py
        alembic/script.py.mako
Please move or remove them before you can switch branches.
Aborting

What's weird is that at first git checkout another_branch git knew about those particular untracked files it later complained about (alembic/README, alembic/env.py, alembic/script.py.mako).

So why git did not delete them?

2 Answers 2

2

Do the directories contain .git subdirectories or files?

-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. This affects also git submodules where the storage area of the removed submodule under .git/modules/ is not removed until -f is given twice.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. This was the problem I had, and this is the command which finally worked: git clean -f -f -d -d
1

There are two kind of untracked files: untracked files and ignored files.

When running as git clean (-f is just to override a "safety" config option), git will only remove untracked files, when running as git clean -x it will remove both untracked and ignored files.

For the checkout issue, it is probably triggered by different .gitignore files in the two branches.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.