Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What type files should be put into .gitignore file in Django project [duplicate]

From my other post, I know the __pycache__ should be put into the .gitignore when I use git.

And in the other post I saw, there are also .pyc and .pyo files.

whether them should all be put into the .gitignore file?

Can we summarize in the Python/Django project, what files should be put into . gitignore file?

like image 425
qg_java_17137 Avatar asked Nov 17 '17 03:11

qg_java_17137


People also ask

What type of file should .gitignore be?

A . gitignore file is a plain text file where each line contains a pattern for files/directories to ignore. Generally, this is placed in the root folder of the repository, and that's what I recommend. However, you can put it in any folder in the repository and you can also have multiple .

What should I add to Gitignore Python?

Editors and other programs you use in your workflow may generate config and backup files that you don't need to track in version control. Git allows you to ignore such files by adding them to the . gitignore file.

What files should I 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.

What would you use a .gitignore file for?

The purpose of gitignore files is to ensure that certain files not tracked by Git remain untracked.


1 Answers

There is a popular web service called Gitignore.io that help developers generate gitignore files for popular framework and languages. You can see the Django one here.

*.log
*.pot
*.pyc
__pycache__/
local_settings.py
db.sqlite3
media

On top of that I would also recommend you to ignore things environment items such as virtualenv, or .env files that are related to the local environment that the code is being run from. This also allow you to store passwords and secrets in environment files, and keep them out of your git repo.

.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

Lastly I would also add the django static folder to the list of files to ignore since it is collected with collectstatic whenever you deploy your code.

like image 62
Marcus Lind Avatar answered Oct 15 '22 20:10

Marcus Lind