programming

CheatSheet wNav Python VScode git and github

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 .venv as 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

  1. Open the project folder in VS Code (File → Open Folder).

  2. Open the integrated terminal (Terminal → New Terminal).

  3. If needed, create the environment using the command in Section 2.

  4. Press Ctrl + Shift + P to open the Command Palette.

  5. Run Python: Select Interpreter.

  6. Select the interpreter located at:

    .venv\Scripts\python.exe
  7. If it is not listed, choose Enter interpreter path → Find, then browse to that file.

  8. 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.

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

  1. Sign in at https://github.com/.
  2. Select New repository.
  3. Enter a repository name.
  4. Choose Private or Public.
  5. 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.
  6. 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


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.

For each new Python project:

  1. Create and open the project folder in VS Code.
  2. Create the environment: py -3.10 -m venv .venv
  3. Select .venv\Scripts\python.exe using Python: Select Interpreter.
  4. Activate the environment in the terminal.
  5. Upgrade pip and install the packages you need.
  6. Create .gitignore so .venv/ and secrets are excluded.
  7. Initialize Git, review with git status, and make your first commit.
  8. Create a GitHub repository, add it as origin, and push main.
  9. Whenever you add or update dependencies, refresh requirements.txt and 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.

Keywords: python programming vscode git github manual