Q:

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.

A:

Use git stash.

git-stash - Stash the changes in a dirty working directory away

See more in the git docs.
If you have untracked new files, be sure to use the -u flag, as includes files git hasn't tracked yet.
Once you're ready to bring your stashed changes back, use git stash pop.
$ git stash -u
$ git checkout <branch>
$ # do work
$ git checkout <oldbranch>
$ git stash pop

A:

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. 

