Getting Started with VS Code

A quick guide for using VS Code with Python and Git

← Back to Resources

Using the Terminal in VS Code

VS Code has a built-in terminal that makes it easy to run Python scripts and Git commands.

Opening the Terminal

  • Use the keyboard shortcut: Control + ` (backtick key, usually under Esc)
  • Or go to the menu: Terminal → New Terminal
  • Or use the Command Palette: Cmd+Shift+P and type "Terminal: Create New Terminal"

Running Python in the Terminal

  1. Create a new file called hello.py
  2. Add some Python code: print("Hello, World!")
  3. Save the file (Cmd+S)
  4. In the terminal, type: python hello.py

💡 Tip: If you have multiple Python versions installed, you might need to use python3 instead of python.

Basic Git Commands

Git helps you track changes to your code and collaborate with others. Here are some basic commands you'll use often:

Setting Up a New Project with Git

# Create a new project folder
mkdir my-python-project
cd my-python-project

# Initialize Git repository
git init

# Create a Python file
touch hello.py

# Open VS Code in the current directory
code .

Basic Git Workflow

# Check status of your files
git status

# Add files to staging area
git add hello.py
# Or add all files
git add .

# Commit your changes
git commit -m "Add hello world script"

# See your commit history
git log

Git in VS Code

VS Code has excellent Git integration:

  • Click the Source Control icon in the sidebar (looks like a branch)
  • Changes to files will be shown there
  • Hover over a file and click + to stage changes
  • Enter a commit message and click the checkmark to commit

Python Basics in VS Code

Creating Your First Script

Create a file named hello.py with the following content:

print("Hello, world!")
name = input("What's your name? ")
print(f"Nice to meet you, {name}!")

Run it by typing python hello.py in the VS Code terminal.

VS Code Python Features

  • Run current file: Right-click in editor and select "Run Python File in Terminal"
  • Run selected code: Select code, right-click, choose "Run Selection/Line in Python Terminal"
  • Python IntelliSense: Get autocomplete suggestions as you type
  • Linting: See errors and warnings in your code as you type

Installing Python Packages

You can install Python libraries using pip in the VS Code terminal.

Basic pip Commands

# Install a package
pip install requests

# Install multiple packages
pip install pandas matplotlib

# Check installed packages
pip list

# Uninstall a package
pip uninstall requests

Using Installed Packages

After installing a package, you can import it in your Python code:

# Example using requests package
import requests

response = requests.get("https://api.github.com")
print(f"GitHub API Status: {response.status_code}")
print(response.json())

Sharing Your Code with Git

Once you've created a project, you might want to share it on GitHub.

Creating a GitHub Repository

  1. Go to github.com/new
  2. Enter a repository name
  3. Choose public or private
  4. Click "Create repository"
  5. Follow the instructions to push your existing repository

Pushing to GitHub

# Add the GitHub repository as a remote
git remote add origin https://github.com/yourusername/your-repo-name.git

# Push your code to GitHub
git push -u origin main

# For subsequent pushes, you can just use:
git push

💡 Tip: VS Code has a built-in GitHub extension that makes this process even easier. Click the Source Control icon, then click "Publish to GitHub".