I am working in a branchX and it has a dozen config files that I do not want to commit. So i marked all the config files as --skip-worktree. Now I want to change to branchY. How do I do it?
I tried
git checkout branchY
and it says
Please commit your changes or stash them before you switch branches.
So i tried to stash them, using
git stash save
but it says
No local changes to save
This is very annoying. Apparently the only solution is
- use
git ls-files -v
to get a list of all the skip-worktree files - for each file, remove the skip-worktree
git stash save
git checkout branchY
git stash pop
- manually resolve any conflict with
--theirs
- for each file, add the skip-worktree flag again
Is there an easier way?
I'm using
git 1.9.1
and it is possible to switch branches with changes in a file that's already in the tree and then skipped withgit update-index --skip-worktree filename
.The file is not changed after the switch (i.e. it is not changed to the version in the branch I switched to).
(I would have thought that this is the behavior since 1.7.7 since its release notes state
* "git stash" learned an "--include-untracked option".
but 1.7.7 was released before you asked the question, so I don't know.)Please note that when trying to switch to a branch that doesn't have the file git still complains with