VS Code has built-in Git support, making it easy to initialize repos, stage changes, commit, and push—all from the editor. Follow these steps to get started.
✅ Prerequisites
- Git installed on your machine
Download from git-scm.com and install - Visual Studio Code installed
Download from code.visualstudio.com
Step 1: Verify Git Installation
Open your terminal (Command Prompt, PowerShell, or integrated terminal in VS Code) and run:
git --version
You should see your Git version. If not, install Git and restart VS Code.
Step 2: Open Your Project Folder in VS Code
- Launch VS Code
- Click File > Open Folder
- Select your project folder or create a new one
Step 3: Initialize Git Repository (If Not Already a Git Repo)
Open the Source Control panel on the sidebar (icon looks like a branch or press Ctrl+Shift+G
) and click Initialize Repository.
Step 4: Configure Git User (First Time Only)
Set your name and email, which will appear in commits:
git config --global user.name "Your Name"
git config --global user.email "yo********@ex*****.com"
You can run these in VS Code’s integrated terminal (`Ctrl+“).
Step 5: Make Changes, Stage, and Commit
- Make edits to your files
- Go to Source Control (
Ctrl+Shift+G
) - You’ll see changed files listed
- Click the + icon next to files to stage them
- Enter a commit message at the top
- Click the ✔️ (checkmark) to commit
Step 6: Connect to a Remote Repository (GitHub, GitLab, etc.)
If you have a remote repo URL, add it by running in the terminal:
git remote add origin https://github.com/username/repo.git
Step 7: Push Your Commits
Push your commits with:
git push -u origin main
(Replace main
with your branch name if different.)
VS Code will prompt for credentials if needed.
Bonus: Using Git Features in VS Code
- Branches: Switch or create branches in the bottom left corner or via the Command Palette (
Ctrl+Shift+P
>Git: Checkout to...
) - Pull: Use
Git: Pull
from the Command Palette or from the...
menu in Source Control - Merge & Resolve Conflicts: VS Code provides inline conflict resolution UI
Summary Table
Step | Action |
---|---|
Install Git | git-scm.com |
Verify Git | git --version in terminal |
Open folder in VS Code | File > Open Folder |
Initialize Git repo | Source Control panel > Initialize Repo |
Configure user | git config --global user.name/email |
Stage & commit changes | Source Control panel |
Add remote | git remote add origin <repo-url> |
Push | git push -u origin main |