1

Whenever I try to checkout to a new branch I get the following message:

$ git co my branch
error: Your local changes to the following files would be overwritten by checkout:
        .vscode/c_cpp_properties.json
        .vscode/launch.json
Please commit your changes or stash them before you switch branches.
Aborting

If I run $ git status

$ git status
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean

I saw other posts about git the first error message, but nothing solved my problem, which I believe is more git update-index --skip-worktree related.

The only option left was git checkout -f which I didn't try because I would rather not force things.

I tried git git stash save .vscode/launch.json

$ git stash save .vscode/launch.json
No local changes to save

These files are among the ones I git update index --skip-wortreeed:

$ git ls-files -t | grep "S "
S .vscode/c_cpp_properties.json
S .vscode/launch.json
S .vscode/settings.json
S CMakeSettings.json
S msvc_build.bat

I saw a few other posts about this error, but none seemed related to update-index --skip-worktree

The only option I haven't tried yet is checkout -f which I am quite reluctant to use, because I don't like to force things whenever possible.

ecstrema
  • 543
  • 1
  • 5
  • 20
  • The entire point of `--skip-worktree` is that those files don't show up in your `git status` and your stashes. Use `git update-index --no-skip-worktree .vscode/launch.json` to undo the skip-worktree – Omer Tuchfeld Mar 13 '20 at 16:08
  • Does this answer your question? [Handling changes to files with --skip-worktree from another branch](https://stackoverflow.com/questions/35690736/handling-changes-to-files-with-skip-worktree-from-another-branch) – Omer Tuchfeld Mar 13 '20 at 16:11
  • @Omer exactly, I don't want to care about them, so why do I get this error on git checkout? – ecstrema Mar 13 '20 at 16:28
  • 2
    `--skip-worktree` mostly means YOUR CHANGES don't get committed/pushed/stashes/status'ed. It does not stop git from letting you know of conflicts between your local state and the remote state. See this: https://compiledsuccessfully.dev/git-skip-worktree/ . Maybe `.gitignore` will be a better option for you if those files are completely personal and meaningless to synchronize inside git – Omer Tuchfeld Mar 13 '20 at 17:24
  • 2
    This is another useful approach (see linked comment, not post): https://old.reddit.com/r/git/comments/7jvuaz/help_with_conflict_between_updateindex/dr9upia/ – Omer Tuchfeld Mar 13 '20 at 17:26

0 Answers0