3

in my Django project,i have already .gitignore file in root as well in django project but when i fire git status or git add . It adding all __pycache__ db.sqlite3 in repository. i need to remove those two things from my project. please help.!

I tried all things like *.sqlite3, mom/*.sqlite3, mom/db.sqlite3 and db.sqlite3 in my both .gitignore file respectively. But anything not work in any directory.

here is my main git ignore file .gitignore

media
*.sqlite3
**/__pycache__/**
*.pyc

here is my another git ignore file .gitignore

media
db.sqlite3
**/__pycache__/**
*.pyc

I also tried many possibilities from online resources but anything not working

file structure

MOM-PROJECT(local Repo)
|
├───MOM (main project)
|   ├───media
|   │   └───media
|   ├───MOM
|   │   ├───migrations
|   │   └───templatetags
|   ├───userprofile
|   │   └───migrations
|   │       └───__pycache__
|   ├───templates
|   │    ├───MOM
|   │    ├───userprofile
|   │    └───base.html
|   ├───manage.py
|   ├───requirements.txt
|   ├───db.sqlite3
|   └───.gitignore [another created after main]
|
├───README.md
├───.git
└───.gitignore [Main]

list adding file of git add command

    modified:   .gitignore
    new file:   mom/.gitignore
    new file:   mom/db.sqlite3
    modified:   mom/meeting/admin.py
    modified:   mom/meeting/views.py
    modified:   mom/static/js/meetingtext.js
    ...

Umm Actually first i created .gitignore file in at main folder where .git folder(in project) exist. my media folder automatically removed and that worked fine. but when i added mom/db.sqlite3 or *.sqlite3 in main .gitignore it's not ignoring therefore i created another .gitignore file inside my project folder where db.sqlite3 is exist. but that also not ignoring my db.sqlite3 file

please suggest me what i need to do. please don't suggest me to use Smart-Git or any other GUI option. right now i m learning phase so i need all thing over commandline

1
  • 1
    For the ones listed as new file, run git rm --cached to remove them from the index—you've added them to the index (though not yet committed, luckily), so now putting the names into .gitignore does not take them out again. Commented Mar 5, 2020 at 21:58

2 Answers 2

8

I had the same issue but found out that my problem was that I had already tracked and committed the db.sqlite3 file in previous commit, which made it impossible for git to ignore when I later added it to the .gitignore.

I think this is not your case but maybe it can give you some hints towards a solution.

To untrack the file without deleting the local file I used:

git rm -r --cached db.sqlite3

After this, the .gitignore is doing the job as intended.

Sign up to request clarification or add additional context in comments.

Comments

0

Remove the *s.

If you specifically want to ignore the pycache and db.sqlite3 files, just add

__pycache__/
db.sqlite3

to your .gitignore file. Alternatively search for django .gitignore files and sample from there.

If you want to know in depth on the gitignore file check out https://git-scm.com/docs/gitignore

1 Comment

Thanks for answer, it not work till it adding the db.sqlite3 i give in my question see..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.