dredh dredh - 21 days ago 5
Git Question

Git checkout branch without commit

I built a new file named test.txt in the master branch.

However,when I checkout into the test branch without commit it.

But I can also see it in the test branch



Why?

tom tom
Answer

Untracked files are left as they are when switching branches. To make test.txt part of the master branch (so that when you checkout the test branch it disappears), you need to add it using git add test.txt and commit using git commit.

If the untracked files were removed when you switched branches, they would be gone forever because they aren't committed. Git tries pretty hard to prevent that from happening.