I have A branch which is waiting for MR(changes pushed to remote branch), at the same time I want to open new branch B and continue working(weekend). So I create new B branch when I am in A branch. But when I do changes in branch B, A also get those changes. So my question is how I can create a copy of that branch without having any connection with changes and commits?
Asked
Active
Viewed 158 times
0
-
`But when I do changes in branch B, A also get those changes. ` - why? – Arkadiusz Drabczyk Sep 26 '20 at 19:12
-
Are you sure A is changing with B? – Shradha Sep 26 '20 at 19:15
-
Sounds weird to me, did you switch branch and commit to the right branch? – Hung Vu Sep 26 '20 at 19:15
-
Try to type `git branch`, and check that you are really in branch B. Also, how do you see that branch A has the same changes as branch B? Based on what do you have such conclusion? – kosist Sep 26 '20 at 19:48
-
So when I do changes in B and try to checkout A branch it asks to add and commit or need to stash save, If I do add and commit then it allows to switch to A branch. And when I am in A branch I see those changes in my vscode "Source Control" section – Russel Oct 02 '20 at 04:52
1 Answers
1
It sounds like you're seeing changes to your working copy that have not been committed to a branch yet. As such, it could appear that the a file is also "Modified" for another branch when you switch branches.
Here's an example that shows you can swap between branches and "carry over" modifications to a file (test.txt
) since those changes haven't been committed to any branch yet.
zrrbite@ZRRBITE MINGW64 /d/dev/git/branchtest (newbranch)
$ git st
## newbranch
M test.txt
Switching back to master we see the same change, since it hasn't been comitted anywhere yet.
zrrbite@ZRRBITE MINGW64 /d/dev/git/branchtest (master)
$ git st
## master
M test.txt

zrrbite
- 1,180
- 10
- 22