Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot checkout branch or remove problematic files

I have 2 branches in my Java project: master and refactor. I've finished working on refactor so now would like to checkout master and merge refactor into master. While working on the refactor, I also added some files to .gitignore (one of them was .idea) and now I get:

[michal@michal-pc MCleaner]$ git checkout master
error: The following untracked working tree files would be overwritten by checkout:
.idea/description.html
.idea/misc.xml
.idea/modules.xml
.idea/project-template.xml
.idea/vcs.xml
Please move or remove them before you switch branches.
Aborting

I've read many posts and nothing works. How can I remove those files without accessing master branch? Is there a way to fix that? Please provide cmd commands if you can, I'm still new to git.

Here is the output from git status:

On branch refactor
Your branch is up-to-date with 'origin/refactor'.

Untracked files: (use "git add <file>..." to include in what will be committed)
  .idea/
  target/

nothing added to commit but untracked files present (use "git add" to track)
like image 564
ohwelppp Avatar asked Feb 06 '23 06:02

ohwelppp


2 Answers

Add the following to .gitignore

.idea

and remove this directory

git rm -r .idea

Then commit changes.

like image 88
Roman C Avatar answered Feb 08 '23 15:02

Roman C


First run

get checkout <branch_name>

The result will be something like the following

error: The following untracked working tree files would be overwritten by checkout:
        .idea/codeStyles/Project.xml
        .idea/codeStyles/codeStyleConfig.xml
        .idea/workspace.xml
Please move or remove them before you switch branches.
Aborting

If you're ok to lose any data in those files (THEY WILL BE OVERWRITTEN) go ahead and run

get checkout <branch_name> --force
like image 45
MattCochrane Avatar answered Feb 08 '23 16:02

MattCochrane