Python Virtual Environment (venv), VS Code, Git & GitHub Cheat Sheet
Windows 10/11 · PowerShell and Command Prompt · Python 3.10+
1. Essential commands — quick reference
Run these from the VS Code terminal or a terminal opened in your project folder.
Task PowerShell Command Prompt (CMD)
Check Python version python --version python --version
List installed Python py -0 py -0
versions (Windows
launcher)
Create a venv using py -3.10 -m venv .venv py -3.10 -m venv .venv
Python 3.10
Activate the venv .\.venv\Scripts\Activate.ps1 .venv\Scripts\activate.bat
Deactivate the venv deactivate deactivate
Install a package python -m pip install PACKAGE python -m pip install PACKAGE
Save installed packages python -m pip freeze > requirements.txt python -m pip freeze > requirements.txt
Install packages from python -m pip install -r requirements.txt python -m pip install -r requirements.txt
the list
Check which Python is where.exe python where python
running
Check Git version git --version git --version
Initialize Git in this git init git init
folder
See changed files git status git status
Stage all changes git add . git add .
Commit staged changes git commit -m "Describe changes" git commit -m "Describe changes"
Push the current branch git push -u origin main git push -u origin main
to GitHub
Pull latest changes git pull git pull
Clone a GitHub git clone REPOSITORY_URL git clone REPOSITORY_URL
repository
Tip: Use
.venvas the environment folder name. VS Code commonly detects it automatically, and the leading dot keeps it visually tucked away.
2. Create a project and its virtual environment
A. Create or open your project folder
Example using PowerShell:
mkdir MyPythonProject
cd MyPythonProject
Or create the folder in File Explorer and open it in VS Code with File → Open Folder.
B. Create the virtual environment
Use the Python version you want your project to run:
py -3.10 -m venv .venv
If you want the default Python version registered with Windows:
python -m venv .venv
This creates a .venv folder containing an isolated Python interpreter
and package installation area. Create the environment once per project;
do not create a new one every time you open the project.
C. Activate it
PowerShell:
.\.venv\Scripts\Activate.ps1
Command Prompt:
.venv\Scripts\activate.bat
When active, the terminal prompt normally begins with (.venv).
D. Confirm the environment is active
python --version
python -c "import sys; print(sys.executable)"
python -m pip --version
The executable path should point into your project’s .venv folder.
E. Upgrade pip and install packages
python -m pip install --upgrade pip
python -m pip install pandas openpyxl
Replace the package names with the libraries your project needs. Using
python -m pip helps ensure pip installs into the interpreter currently
selected by the terminal.
3. Configure the venv in Visual Studio Code
-
Open the project folder in VS Code (File → Open Folder).
-
Open the integrated terminal (Terminal → New Terminal).
-
If needed, create the environment using the command in Section 2.
-
Press
Ctrl + Shift + Pto open the Command Palette. -
Run Python: Select Interpreter.
-
Select the interpreter located at:
.venv\Scripts\python.exe -
If it is not listed, choose Enter interpreter path → Find, then browse to that file.
-
Open a new terminal. VS Code may automatically activate the selected environment.
Important: Selecting the interpreter tells VS Code which Python to
use for running, debugging, and language features. Activating the
terminal environment is a separate operation. Check the terminal prompt
for (.venv) and verify the interpreter path if anything seems wrong.
Run your Python file
Open the .py file and use Run Python File (the play button), or
run:
python your_script.py
To run the file with the debugger, press F5 and select the appropriate
Python configuration if prompted.
Recommended VS Code extensions
Install these from the Extensions view (Ctrl + Shift + X):
- Python — Microsoft: Python language support, interpreter selection, debugging.
- Pylance — Microsoft: code completion, type analysis, and navigation.
- Ruff — linting and formatting for Python (optional, but useful).
4. Git and GitHub setup
Git is the version-control tool installed on your computer. GitHub hosts remote repositories online. You can use Git locally without GitHub, but connecting a remote repository lets you back up and collaborate.
A. Install and verify Git
Install Git for Windows from:
https://git-scm.com/download/win
Then close and reopen VS Code and check:
git --version
B. Set your Git identity
Use the name and email you want associated with your commits. The email should generally be one associated with your GitHub account if you want GitHub to attribute commits to you.
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
Check the settings:
git config --global --list
C. Create a .gitignore file
Create a file named .gitignore in the project root. This prevents your
virtual environment and other generated or private files from being
committed.
Example .gitignore:
# Python virtual environment
.venv/
venv/
# Python-generated files
__pycache__/
*.py[cod]
*.pyo
# Test and tool caches
.pytest_cache/
.ruff_cache/
# Environment variables and secrets
.env
.env.*
# VS Code workspace settings (optional)
# Uncomment if you do not want to share workspace settings
# .vscode/
Do not commit passwords, API keys, tokens, private configuration files, or other secrets. If a secret was committed, deleting it in a later commit does not erase it from the repository history; rotate/revoke the exposed secret.
D. Initialize Git and make the first commit
Run these commands from the project root:
git init
git add .
git status
git commit -m "Initial project commit"
git status lets you review what is staged before committing. If Git
reports that the branch is not named main, you can set it with:
git branch -M main
E. Create a repository on GitHub and connect it
- Sign in at https://github.com/.
- Select New repository.
- Enter a repository name.
- Choose Private or Public.
- For an existing local project, create the GitHub repository
without adding a README,
.gitignore, or license if you have already created those locally. This avoids an unrelated initial-history merge. - Copy the repository’s HTTPS URL.
Connect your local project (replace the example URL with your repository URL):
git remote add origin https://github.com/YOUR-USERNAME/YOUR-REPOSITORY.git
git branch -M main
git push -u origin main
GitHub may prompt you to authenticate through a browser or Git Credential Manager. Follow the sign-in prompt; do not put a GitHub password or token directly into a command.
F. Everyday Git workflow
After editing files:
git status
git add .
git commit -m "Explain what changed"
git push
To retrieve commits made on GitHub or another computer:
git pull
To see recent commits:
git log --oneline
To see configured remotes:
git remote -v
To clone an existing repository onto a computer:
git clone https://github.com/USERNAME/REPOSITORY.git
cd REPOSITORY
py -3.10 -m venv .venv
.\.venv\Scripts\Activate.ps1
python -m pip install -r requirements.txt
5. Useful maintenance and troubleshooting commands
Virtual environment and packages
Command What it does
deactivate Exit the active virtual environment
python -m pip list List installed packages
python -m pip show PACKAGE Show details about a package
python -m pip install --upgrade PACKAGE Upgrade a package
python -m pip uninstall PACKAGE Uninstall a package
python -m pip check Check for broken package
dependencies
python -m pip freeze Display installed packages and
versions
python -m pip freeze > requirements.txt Write package versions to a file
python -m pip install -r requirements.txt Install from a requirements file
Rebuild a damaged or outdated venv
A virtual environment can usually be recreated safely because the
project source files are separate. First deactivate it, then remove only
the .venv folder and recreate it:
deactivate
Remove-Item -Recurse -Force .venv
py -3.10 -m venv .venv
.\.venv\Scripts\Activate.ps1
python -m pip install --upgrade pip
python -m pip install -r requirements.txt
Warning: The removal command permanently deletes the .venv
directory. Confirm you are in the correct project folder and that
.venv is the environment folder before running it. Do not use this
command if you have stored your own source files inside .venv.
PowerShell says script execution is disabled
If PowerShell blocks Activate.ps1, you can either use the CMD
activation command in a Command Prompt terminal, or allow locally
created scripts for your Windows user:
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned
Review the prompt before confirming. This changes the execution policy for your user account. On a company-managed computer, organizational policy may prevent this change; use an approved terminal or ask IT rather than bypassing policy.
Git troubleshooting
Command What it does
git status Shows current branch and
working-tree changes
git diff Shows unstaged changes
git diff --staged Shows staged changes
git branch Lists local branches
git branch -M main Renames the current branch to
main
git remote -v Lists remote repository URLs
git remote set-url origin URL Changes the origin URL
git restore FILE Discards unstaged changes in a file
— use carefully
git restore --staged FILE Unstages a file but keeps its edits
git help COMMAND Opens help for a Git command
6. Recommended project folder layout
MyPythonProject/
│
├── .venv/ # Local virtual environment; do not commit
├── .vscode/ # Optional shared VS Code workspace settings
├── src/ # Application source code (optional layout)
│ └── main.py
├── tests/ # Automated tests (optional)
├── .gitignore # Files Git should ignore
├── README.md # Project overview and setup instructions
└── requirements.txt # Python package dependencies
For a small project, main.py can live directly in the project root.
The src and tests folders are optional organizational choices.
7. Recommended start-to-finish routine
For each new Python project:
- Create and open the project folder in VS Code.
- Create the environment:
py -3.10 -m venv .venv - Select
.venv\Scripts\python.exeusing Python: Select Interpreter. - Activate the environment in the terminal.
- Upgrade pip and install the packages you need.
- Create
.gitignoreso.venv/and secrets are excluded. - Initialize Git, review with
git status, and make your first commit. - Create a GitHub repository, add it as
origin, and pushmain. - Whenever you add or update dependencies, refresh
requirements.txtand commit that change.
The key idea: Each project gets its own .venv, its own dependency
list (requirements.txt), and its own Git repository. This keeps
projects isolated and makes them easier to reproduce on another
computer.