I have a couple different virtual environments in a project, e.g.
~/project_dir/sub_dirs/venv/...
Adding */venv/*
to the .gitignore file does not prevent the virtual environment folders and their contents from being excluded. What is the correct syntax to prevent these virtual environment directories from being added to the git repository?
gitignore folder just add the name of the folder with a slash at the end. This will ignore all sub directories in the venv folder.
gitignore is a plain text file in which each line contains a pattern for files or directories to ignore. It uses globbing patterns to match filenames with wildcard characters. If you have files or directories containing a wildcard pattern, you can use a single backslash ( \ ) to escape the character.
You should add it to gitignore file. Then, you should create requirements. txt file and populate it with the packages you have installed. Then, on your production server, create the virtual environment and run pip install -r requirements.
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 .
per https://github.com/github/gitignore/blob/master/Python.gitignore
venv/
does the trick for sub-directories.
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