0

I'm using Git as my version control software. I've initialized and made the initial commit to my local repository. Then I'm creating another branch for an UI update as following.

git checkout -b "ui-update"

The issue is, when I make a change to the ui-update branch and switch back to my master branch (without comiting those changes), the changes that are made, are also reflected in my master branch. Also, it is not giving an error when I'm switching to my master branch. This is how I switch to my master branch.

git checkout master

However, when I make a commit to the ui-update branch, those changes are only reflected in that branch (not in master).

Is this the default behavior of Git? Or am I doing something wrong here?

A.M.N.Bandara
  • 1,490
  • 15
  • 32
  • 2
    I think [this](https://stackoverflow.com/questions/8526279/git-allows-for-branch-change-with-unstaged-changes) explains everything – Panayiotis Poularakis Jul 11 '17 at 10:45
  • 1
    Yes, that is the default behaviour of Git, you are not doing anything wrong. – 1615903 Jul 11 '17 at 10:56
  • The link shared by @PanayiotisPoularakis explains my situation well. As described in there, all I have to do is switch back to my ui-branch and commit those changes. Once I've done that, those changes will not be affecting the master branch anymore. – A.M.N.Bandara Jul 12 '17 at 04:08

1 Answers1

0

Modifications are not a part of a branch while you don't commit them.

So, before your

git commit -m "my commit"

all you do is not binded on anything and you can checkout a branch taking your modifications with you without affecting the current branch

Saifer
  • 350
  • 4
  • 16
  • Actually, the modifications I made are affecting both branches. – A.M.N.Bandara Jul 12 '17 at 03:54
  • They are in the branch where you checkout, the actual one, so it looks like they are in every branch, because the branch you are looking everytime is the current branch. When you will commit them, they will be just in the branch where u do. – Saifer Jul 12 '17 at 14:45