Alex J
Alex J

Reputation: 1567

Git branch switching does not change code folder files

This is a follow up to this question.

I cloned the remote master project folder using git clone [email protected]:TEST command. from the Git root, I did a cd Test command to move into that folder. I then created a branch using git checkout -b myBranch. Now on the git bash it shows that i'm in the new branch. I created a test.txt file in the Test folder and then switched my branch to master. I still see the text file. Isn't Git supposed to not show the test.txt since it not part of master. Do I need to commit my changes in the branch if this has to happen.

I thought initially this may have happened because it is not part of my .net project (that I have in the master and branch). But the same happened when I tried to add a file to mybranch. When I switch my master, I still see the changed icon for the folders in the fie system.

What am I missing? Thank you for all your help as I have spent a lot of time trying to figure out Git now. Every time I think I have got it, there is always something.

Upvotes: 12

Views: 6846

Answers (1)

Andrew Marshall
Andrew Marshall

Reputation: 97004

No it's not part of your master branch, but it's not part of myBranch either. It is untracked, because you never committed the file. Running git status you'll see it listed as untracked. Since it was never staged or committed, Git doesn't (and can't) manage its existence, so it stays there regardless.

Further, modified files remain between branches if they can. Else Git will give you an error when switching branches about a dirty working tree. This is, again, because Git has no internal copy of those changes, they exist only in your filesystem, and not within Git till they are committed.

Upvotes: 18

Related Questions