why? When creating a branch with git branch, it doesn't work.
-
wrote on 4 Feb 2023, 04:23 last edited by
I have the following doubt, when I create a new branch called dev: git branch "dev", and I make changes in this branch, they are also reflected in the main branch, which should not happen, because when changing branches, with git checkout main, there are also the changes I made in my dev branch, could someone give me a suggestion as to why this is happening.
I leave the screen shot, in case it helps.
As an example I only entered a comment in my main.cpp file, being in the dev branch, and as I commented above, when I switch to the main branch the comment also appears and indicates that there were changes in the main.cpp file, thanks in advance for your answers. -
I have the following doubt, when I create a new branch called dev: git branch "dev", and I make changes in this branch, they are also reflected in the main branch, which should not happen, because when changing branches, with git checkout main, there are also the changes I made in my dev branch, could someone give me a suggestion as to why this is happening.
I leave the screen shot, in case it helps.
As an example I only entered a comment in my main.cpp file, being in the dev branch, and as I commented above, when I switch to the main branch the comment also appears and indicates that there were changes in the main.cpp file, thanks in advance for your answers.@lincoln said in why? When creating a branch with git branch, it doesn't work.:
when I create a new branch called dev: git branch "dev", and I make changes in this branch, they are also reflected in the main branch
You did not make any changes in your "dev" branch. You only made changes in your local copy of the file.
If you want the changes to become part of the "dev" branch, then you must commit your change when the "dev" branch is checked out.
After you commit it, then
git checkout main
will no longer show the change. -
wrote on 4 Feb 2023, 07:30 last edited by ChrisW67 2 Apr 2023, 07:46
git branch dev
creates a branch but does not switch your working copy to that branch. Follow up with one ofgit switch dev
orgit checkout dev
.You can create a branch and switch your working copy in one action
git checkout -b dev
Edit: Actually @JKSH is closer to answering the particular issue.
1/3