How to Set Up Git with Visual Studio Code

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


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

  1. Launch VS Code
  2. Click File > Open Folder
  3. 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

StepAction
Install Gitgit-scm.com
Verify Gitgit --version in terminal
Open folder in VS CodeFile > Open Folder
Initialize Git repoSource Control panel > Initialize Repo
Configure usergit config --global user.name/email
Stage & commit changesSource Control panel
Add remotegit remote add origin <repo-url>
Pushgit push -u origin main
Sharing Is Caring:

Leave a Comment