Question

I have created on branch named as "sub-branch". I am creating on file test1.txt after switching to sub-brnach using command git checkout sub-branch. Now when i switch to master branch using command git checkout master without committing the changes of the sub-branch, the file test1.txt is also shown in master branch.

Why the file test1.txt is shown in master branch,since i have created test1.txt file in sub-branch so it should be presented in sub-branch only.why git is showing test1.txt file in master branch also when i do git checkout master???.

Thanks

Was it helpful?

Solution

As long as you don't commit it in subbranch, it is a private (untracked) file, not attached to any branch.

So when you switch back, that file is ignored and unchanged.

A git checkout -f master would remove local changes (but not untracked files).

A git clean would, but again, that mean you would loose the file. Start with a git clean -n to see a preview.

A git stash would save your untracked file (until you apply it again with a git stash pop)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top