Search code examples
gitbranchgit-branchworkspacegit-checkout

Checkout second Git branch without losing local changes


I have checked out a particular branch from my master. I created new classes propery files etc. in my local Eclipse and did the testing. I have not added/committed those classes/files to my local git repo. So after this successful prototype testing if I want to switch to another branch, how can I do it without losing local changes.

Once I check out the second branch my local changes will be overwritten? I am not sure if my changes will have to be discarded before the checkout of second branch to be possible.


Solution

  • Well it is not certain you would lose changes (and in fact if you were to, git checkout would warn you), but it would be best to either stash your changes with git stash or just go ahead and commit your changes before checking out the other branch.