'.gitignore syntax - how to exclude virtualenv sub-directories?
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?
Solution 1:[1]
- Create in your current project's folder ".gitignore" file
- For example, if you have some folders as "venv" and ".vscode" than you just add their names in ".gitignore" file: venv/ .vscode/
Solution 2:[2]
I Had similar problem, But i'm trying to exclude 'vir-2.7/' which is not working. Seems the '.'(dot) was interrupted differently by git, so i have changed the directory name to 'vir_2_7', to fix it.
Solution 3:[3]
Solution 4:[4]
Inside the .gitignore folder just add the name of the folder with a slash at the end.
Example: venv/
This will ignore all sub directories in the venv folder.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Magomed Shamaev |
| Solution 2 | MohanBabu |
| Solution 3 | Diego Venâncio |
| Solution 4 | Winfred |

