Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (19.4k points)
edited by

I was working on a git branch and was ready to commit my changes, so I made a commit with a useful commit message. I then absentmindedly made minor changes to the code that are not worth keeping. I now want to change branches, but git gives me,

error: You have local changes to "X"; cannot switch branches.

I thought that I could change branches without committing. If so, how can I set this up? If not, how do I get out of this problem? I want to ignore the minor changes without committing and just change branches.

1 Answer

0 votes
by (119k points)
edited by

If you want to discard the changes,

git checkout -- <file>

git checkout branch

If you want to keep the changes,

git stash save

git checkout branch

git stash pop

Also, check out this Git Tutorial to know more.

Browse Categories

...