Reputation: 2175
Changing a branch with git checkout usually takes uncommitted changes to the new branch (and tries to merge them in, or fail).
Sometimes I'm working in a feature branch, and I am not quite ready with whatever I'm working on to commit them, but need to switch branches because I need to work on something else.
If this is just a "quick look" stashing, changing branches there and back and unstashing works.
If this is something that requires more time (in some cases two days or even a week), stashing is not really a good option, as other stuff may get stashed, so it's not exactly straight-forward to find which stash I am looking for), and even after changing back to the old branch, sometimes I even forget that I had a half-solution already. Committing everything as a "wip" commit, and then later soft-resetting or amending that would be an okayish workaround, but it's still a workaround, and again may be forgotten that a wip commit is there, messing up the git log, unless one again spends time and effort to rebase stuff.
So the question is:
Is it possible to change branches, without committing changes, and without taking them to the new branch? And when changing back, the changes would be there either staged or unstaged?
Upvotes: 0
Views: 132
Reputation: 11977
I don't think that is possible using just git branch
. You should, however, be able to use git worktree
in order to have multiple versions of your repository checked out in different directories.
Here's a link to the documentation for git worktree
: https://git-scm.com/docs/git-worktree
Upvotes: 1