Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am learning git. I have created a new branch named 'development' and in that branch when I am creating a file it is automatically adding to the main branch even I did not staged that file.

In the main branch there was two files named one.txt and two.txt.

I just checkout to development branch by

git checkout development

Then I created a file named three.txt by echo three > three.txt in the development branch. I did nothing after creating the three.txt file. I even didn't staged the file.

After crating the file I checkout to the main branch and I saw three.txt there. But how it is possible?

I don't want to have the file in main branch before I merge it.

This is happening like sync system. If I staged a file form any branch it is automatically staged in the main branch and vice-versa. What is the solution? How can I solve this problem? Help me please.

OS: Windows 10

git version: 2.32.0

I used both power-shell and git-bash and getting same result.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
880 views
Welcome To Ask or Share your Answers For Others

1 Answer

If you run git status you'll see this file in next section:

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)

Also you can see hint here what to do next with you file, (you can stash your file as well).

Technically your file doesn't belong to any branch yet, b/o you didn't commited it yet, so git will keep track of this file with purpose don't lose your changes even when you change branch.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...