MeltingDog MeltingDog - 1 year ago 72
Git Question

Git: branch-x changes have become part of branch-y?

I don't know how it happened, but I am on a 'branch-x' and the files I have changed belong to `branch-y'.

I cannot

git checkout branch-Y
because the I have un-committed changes and I don't want to commit them in branch-x.

How can I return to branch-y with my changes intact?

Answer Source

You could stash your changes:

git stash

Then checkout the correct branch:

git checkout branch-Y

And then unstash the changes in the correct branch:

git stash pop

Depending on what types of changes you made in your initial branch, you might need to use additional switches on stash command (e.g. --include-untracked). You can read more about stash command in Git docs.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download