• Register
0 votes
32 views

Problem :

I added the folder to the .gitignore file.

Once I do the git status it tells me

# On branch latest
nothing to commit (working directory clean)

But when I try to change my branches I get the below:

My-MacBook-Pro:webapp marcamillion$ git checkout develop
error: The following untracked working tree files would be overwritten by checkout:
    public/system/images/9/thumb/red-stripe.jpg
    public/system/images/9/original/red-stripe.jpg
    public/system/images/8/thumb/red-stripe-red.jpg
.
.
Please move or remove them before you can switch branches.
Aborting

This is how the .gitignore file looks like:

.bundle
.DS_Store
db/*.sqlite3
log/*.log
tmp/**/*
public/system/images/*
public/system/avatars/*

How do I get this working for me so I can switch my branches without deleting those files?

by (3.9k points)  

1 Answer

0 votes

Solution :

It appears like you want your files ignored but they are already committed. The .gitignore has no effect on your files that are already in your repo so they must be removed with git rm --cached. A --cached will prevent it from having any effect on the working copy and it will just mark it as removed the next time you commit. After your files are removed from a repo then your .gitignore will prevent them from being added again.

But you have another problem also with your .gitignore, you must be excessively using wildcards and that is causing it to match less than the expect it to. Instead of that lets change your .gitignore and try as given below.

.bundle
.DS_Store
db/*.sqlite3
log/*.log
tmp/
public/system/images/
public/system/avatars/
by (36.1k points)  
...