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?
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 .
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.
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.
The purpose of gitignore files is to ensure that certain files not tracked by Git remain untracked.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With