Search code examples
gitbranch

Git is acting weird


I'm using git actually for a project. My problem is that Git is acting weird (maybe I'm wrong so let me know please). So I just created a branch :

git checkout -b my_branch

I created a file in that branch. But then when I come back to my master branch and that I do a git status :

git checkout master
git status

I can see the file I created in my_branch, in the untracked file list of the master branch.

Is Git suppose normally to not showing me the change from my_branch till I merge?

Indeed, I didn't add yet my file but just created it. It's more clear now because of you.


Solution

  • You just created a file right? You didn't git add and git commit it in the my_branch. Unless you commit the file, the file is not part of the branch you are in, and when you switch branches, the file will still be there in the working directory as untracked.

    This is even applicable to files already in the repo. If you make changes to a file, and switch branches, the change will still be there ( barring conflicting changes across branches )