Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a .gitignore file for a Django website

I'm ready to push my existing Django project (which i've been running in a local environment) to a Bitbucket repository so I can run it on a public server. At the moment I feel like there's a lot of files created in local development that needs to be added to .gitignore.

I found this .gitignore file on github however I still feel it's missing some things, for example it doesn't seem to remove files from each migrations folders. There's also a lot of stuff there that I don't know what they do - I understand not all of it is needed. Any advice is appreciated.

like image 416
Zorgan Avatar asked Dec 03 '17 08:12

Zorgan


People also ask

How do I create a Gitignore file in Django?

gitignore file at the root of your Django project and put these files and directories there, as follows: # . gitignore # Project files and directories /myproject/local_settings.py /myproject/static/ /myproject/tmp/ /myproject/media/ # Byte-compiled / optimized / DLL files __pycache__/ *. py[cod] *$py.

What files to Gitignore Django?

If you are using Git for version control, you need a Gitignore file to ignore all files that don't matter and shouldn't be in your git repository. Think of your virtual environment and all the . pyc files. Those are both generated and can be generated by anyone that has access to your code.


2 Answers

You could consider a gitignore tailored for Django project instead.

And don't forget that, if you already have added and committed a folder content, you will need to remove them before your .gitignore can take effect.

git rm --cached -r afolder/

However, by default, migration is not ignored. (you can skip some of those migration steps)
As pointed out by Ora in the comments, see "Should I be adding the Django migration files in the .gitignore file?".

So, do not add migration/ to your .gitignore.

like image 126
VonC Avatar answered Oct 01 '22 05:10

VonC


The best example I have found is here: https://djangowaves.com/tips-tricks/gitignore-for-a-django-project/

This is not my work!!! I don't want to take credit for someone else's good collection! Not everything in there is relevant. The author documents it well, though, so you can boil it down to what you need.

I would also add:

**/migrations
*.DS_Store
**/__pycache__
**/.DS_Store
like image 36
merlit64 Avatar answered Oct 01 '22 05:10

merlit64