Reputation: 29
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?
Upvotes: 2
Views: 814
Reputation: 3616
when you run git status
in master branch, it shows test.txt is a "untracked file", that means test.txt is not under management of git, then what do you expect git do for you?
Upvotes: 1
Reputation: 22989
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.
Upvotes: 2