Why does git checkout master apply changes from new branch?

by thelma.stanton , in category: General Help , a year ago

Why does git checkout master apply changes from new branch?

Facebook Twitter LinkedIn Telegram Whatsapp

2 answers

Member

by alivia , a year 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.

Member

by samara , 8 months ago

@thelma.stanton 

Git checkout master does not apply changes from a new branch because when you create a new branch in Git and switch to it, you are essentially moving your HEAD pointer to the new branch. This means that any changes you make in the new branch will stay in that branch and will not affect the master branch.


When you switch back to the master branch using git checkout master, Git will not apply the changes from the new branch to the master branch automatically. If there are changes in the new branch that conflict with the state of the master branch, Git will prompt you to either commit, stash, or discard the changes before allowing you to switch to the master branch.


In summary, Git is designed to separate changes made in different branches, and when you switch branches, the changes made in one branch do not automatically apply to another branch. Git ensures that changes are managed and merged intentionally to maintain code integrity.