1

I created a new branch to my project, but when I try to switch to the new branch I get the error:

The following untracked working tree files would be overwritten by checkout

..with basically all of my files in the description of the error.

Every solution I've found on the Internet, and on this website didn't work. I even tried to use git and use the commands that were suggested in most of the topics I saw, but none of them work. I can't force the checkout, I can't clean the repo, I'm stuck.

The only thing I haven't done, is to try to commit in the master branch, but I don't want to do that because those files aren't ready for a push.

Do you have any Idea how I can switch branches ?

SherylHohman
  • 16,580
  • 17
  • 88
  • 94
Nyvlem
  • 13
  • 2
  • 1
    You will need to either delete these files or put them under git's control. If you don't want to commit to master, you can create a new branch and commit these files to that branch. Then your repo will be clean and you can safely switch. – Adrian W Sep 05 '18 at 12:50
  • Have you tried `stash`ing the files before changing branches? – SherylHohman Sep 05 '18 at 16:29
  • Can you list *which* StackOverflow questions did *not* work for you, and why: *"every solution I found... did not work"* does not help us differentiate your issue from others'. As quoted from [How to ask](https://stackoverflow.com/help/how-to-ask): `Even if you don't find a useful answer elsewhere on the site, including links to related questions that haven't helped can help others in understanding how your question is different from the rest. `You can `edit` to supply additional information. Thanks! – SherylHohman Sep 05 '18 at 16:55
  • Also, do the answers or question here: https://stackoverflow.com/questions/6829671/git-says-the-following-untracked-working-tree-files-would-be-overwritten-by-che provide any insights as to what's happening ? Ie. If you already committed to your *new* (but not just newly created) branch, could it be that checking out your new branch would essentially delete saved files of the same name. Or can you create another new branch? I guess enough details of this exact issue and it's causes (how you got there) are not clear to me.. – SherylHohman Sep 05 '18 at 18:05

2 Answers2

1

The right way to do this is to use git stash push, then switch to the new branch and pop the stash you created. You'll first need to add your changes.

Like this:

git add .
git stash push
git checkout newBranch
git stash pop
AsherMaximum
  • 942
  • 2
  • 11
  • 17
0

So, I downloaded ToritoiseGit and putted the files to my changeset using the "add" function. This worked well and I can now switch to any branches with any other software.

Nyvlem
  • 13
  • 2