Reputation:
I am trying to switch branch. I have created one branch called nilay using:
git checkout nilay
I can switch to this branch very easily. I can also switch to master branch.
I am trying to edit all of my code in my branch nilay, but in my visual code editor, when I am trying to checkout, I am getting this error:
error: Your local changes to the following files would be overwritten by checkout:
I want to switch my branches; for example when I use:
git checkout nilay
I want my code of this branch as it is, and when I change it, it should stay there. And when I switch to master using:
git checkout master
I should see the master code, but when I am switching I am getting errors. What is the best way to switch branches?
Upvotes: 1
Views: 7844
Reputation: 198294
You are switching correctly. However, Git is telling you that you have uncommitted changes on the currently checked out branch, and if you switch branches those changes will be lost.
You can git commit
those changes to keep them, or abandon them with git reset --hard
, or defer the decision with git stash
(and return to those changes later with git stash pop
).
Upvotes: 3