3 ms·
> in git, for example, why can’t i switch branches with uncommitted changes? it makes no sense why i can’t do that, but yet, there it is. Because the working t
by merlincorey 9y ago
> in git, for example, why can’t i switch branches with uncommitted changes? it makes no sense why i can’t do that, but yet, there it is.
Because the working tree having uncommitted changes being blown away would be terrible data loss or a conflicting merge, so when that could happen, git prevents it.
Use `git stash` to stash your uncommitted changes before switching branches and you'll no longer have data loss.
If you want to apply those changes again use `git stash pop`.
If you don't want those changes use `git stash drop`.
Why isn't there a commandline option to checkout a branch and do a stash operation at the same time?
Because no one has needed it enough to add it.
- coldacid 9y ago>Because no one has needed it enough to add it. Or because those that did need it whipped up a quick and dirty alias to cover that use case.
- chopin 9y agoI wouldn't want this. This would only be useful if the stash is automatically popped when switching back.
- chrismcb 9y agoI think the implication is that switching branches shouldn't blow away your uncommitted changes. And one shouldn't have to stash their changes to switch branches.