How can you git-checkout
without overwriting the data?
I run
git checkout master
I get
Git does a 2-way merge of uncomitted changes when switching branches (using git checkout
), but ordinarily it does only trivial (tree-level) merge.
Besides git-stash
solution by Karl Voigtland, you can give additional options to git checkout, choosing one of the following options:
Tell git to try harder to merge uncomitted changes into branch you switch to with -m
/ --merge
option. With this option, a three-way merge between the current branch, your working tree contents, and the new branch is done, and you will be on the new branch.
Tell git to overwrite uncomitted changes, throwing away local changes with -f
option. Warning: uncomitted changes will be lost!