0

I have a branch name test1 and I make a new branch named as test2 by following command. Currently my branch is test1 I run this command

$ git checkout -b test2 

It creates the new branch and work on that test2 branch. After completing my my task on test2 branch I switch back to my original branch test1 but it also merge the changing of test2 branch that is not good. Because I want to separate the logic of both branches. Now my original branch also become unstable. I just want to know that why test2 code merge in my test1 branch when I checkout?

3
  • This shouldn't happen. Post the whole commands please. Commented Jun 16, 2015 at 6:48
  • @MarounMaroun I just run first command then work on new branch then simple checkout test1 branch. Commented Jun 16, 2015 at 6:50
  • Unless explicitly added files in git aren't under a version control. Am I correct to assume that a file created during test2 being active is still around when switching to another branch? Commented Jun 16, 2015 at 6:56

2 Answers 2

2

Uncomitted changes don't belong to any specific branch, that's why they will just stay in the working directory. When those changes would conflict with changes from the other branch, git checkout will abort and say so.

You have to commit your changes on branch test2. After this, when you checkout test1, those changes will disappear.

Note that people are often reluctant of committing changes because they're not yet finished with their work. In git, it's hardly a problem, because it's easy enough to amend the last commit, or undo it with git reset HEAD^ and recommit with the latest changes.

Sign up to request clarification or add additional context in comments.

Comments

1

I think that you did merge test2 to test1.

Whatever, you can use git commands as follow to clear your test1 branch.

git log # copy the latest commit id before commits you committed on test2 git reset <commit id> # reset to that commit git checkout . # checkout the modifies you merged into test1 from test2 

now the branch test1 is clear

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.