Machinarius
Machinarius

Reputation: 3731

Git branch affects master

I am working on a google maps project on android and i need to update the maps to the new v2 version, thus ive created a branch with

git add -u
git commit -m 'xxxyyyzzz'
git checkout -b MapsV2

Then i realized i needed to fix something really quick on the master branch so i ran

git checkout master

only to find out all of my changes in the MapsV2 branch were intact on the master branch after the checkout.

To give some more context, master is our main branch, whilst MapsV2 is the research branch for the new maps API.

What did i do wrong?

Upvotes: 0

Views: 168

Answers (2)

Ben Butler-Cole
Ben Butler-Cole

Reputation: 2051

(I assume that you were on the master branch before you started the sequence of command you give.)

You made the commit before you created the new branch. So those changes were made to master. You then created the new MapsV2 branch from master, so that branch has the changes as well.

Upvotes: 0

anydot
anydot

Reputation: 1539

By default git checkout will not reset state of your working directory, for this you need to use git reset --hard after checkout. Beware, this will reset both your index and working directory and by doing this you can lost all uncommitted changes!

Upvotes: 3

Related Questions