Why does git checkout master apply changes from new branch?

by thelma.stanton , in category: General Help , 2 months ago

Why does git checkout master apply changes from new branch?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by alivia , 2 months ago

@thelma.stanton 

Git checkout master does not apply changes from a new branch.


When you create a new branch in Git and switch to it using the git checkout command, you are simply changing your current branch pointer to the new branch. This means that any changes you make after creating and switching to the new branch will only affect that branch, not the master branch or any other branches.


However, if you have made changes on the new branch and you attempt to switch back to the master branch using git checkout master, Git may prevent you from doing so if the changes you made on the new branch conflict with the current state of the master branch. Git will ask you to either commit your changes, stash them, or discard them before switching to the master branch. If you choose to stash or commit your changes, they will be preserved and will not be applied to the master branch automatically.