I have a stable master branch, and began working on a dev branch.
Suppose in dev I change a few files, but then want to temporarily switch back to master -- in my case, to run the master code in a debugger to check some code blocks. Then, I'll switch back to dev to continue my work, but in the meantime, I'm not ready to commit
dev.
In this case, I thought staging the dev files via git add src/modified_files*
before git checkout master
would do the trick. But when I compiled the master code, I found that I was mistaken (i.e. the modified files still existed, and were not swapped with the master files).
What is the proper way to do this?
git add
doesn't change your working tree. It prepares the next commit.dev
then switch tomaster
. When you switch back todev
, rungit reset HEAD~1
and Git restores the status of your repo as it is now. It's better than using a stash because a branch is always visible but a stash can be easily forgotten.