Confusion about local branch having updates from parent branch after git pull

24 views Asked by At

(I am relatively new to git, so please excuse any obvious mistakes or questions) How does checking out a secondary branch show changes made to the parent branch that were added after the secondary branch branched off the parent?

For context, let's say branch A branched off master. Now, I make another branch off of A, called B. After B was created, some changes were pushed to A. B does not have these changes. I have branch A checked out locally. I do git stash (because I am not interested in keeping the changes made locally), and then git pull to pull in all the changes made to branch A. Then I want to switch to working on branch B. I git checkout branch B. Now suddenly, I am seeing the changes made to branch A after branch B was created, in my local branch B repo. How is this possible?

As a sanity test, I checked out master, and lo and behold, the additions to branch A were present in master.

Shouldn't checking out a branch only show what is in the branch, regardless of what was on the local repo before the new branch was checked out? We have to either commit or stash any changes before we checkout a new branch, so it's not like this is a safety measure to save work that may not have been saved. Is this git behavior normal, or do I need to fix my git settings?

0

There are 0 answers