In this categoryVS Code Setup ยท 25
- How to Set Up GitHub Copilot in VS CodeStart
- How to Use Copilot Chat and Inline Chat in VS Code
- How to Install and Manage Extensions in VS Code
- How to Install the Continue Extension in VS Code
- How to Install Cline, the Autonomous Coding Agent, in VS Code
- How to Configure Continue with an API Model
- How to Set Up an AI Assistant in VS Code
- How to Run Continue with a Local Model Using Ollama
- How to Run Copilot, Continue, and Cline Together Without Conflicts
- How to Add an MCP Server to Cline
- How to Fix AI Suggestions Not Appearing in VS Code
- How to Install and Trust an AI Extension in VS Code
- How to Install a VS Code Extension from the Command Line
- How to Create a launch.json to Debug a Node.js App in VS Code
- How to Initialize a Git Repository in VS Code
- How to Stage, Commit, and Push Changes from VS Code
- How to Debug a Browser App in VS Code with the Built-in Chrome Debugger
- How to Resolve Git Merge Conflicts in VS Code
- How to Run Build and Dev Commands with tasks.json in VS Code
- How to Add Environment Variables to a VS Code Debug Configuration
How to Initialize a Git Repository in VS Code
Turn a plain project folder into a git repository, make your first commit, and understand the Source Control view, all without typing git commands.
Version control is the safety net that lets an AI assistant make bold changes to your code while you keep the power to undo any of them. VS Code has git built into the Source Control view, so you can create a repository and commit changes with buttons instead of memorizing commands. This guide takes a fresh folder from no history to its first commit.
What you need
- Git installed on your machine (run git --version to check)
- A project folder open in VS Code
- Your git name and email configured (covered below)
Step 1: Set your git identity once
If you have never used git on this machine, set the name and email that will be stamped on your commits. Open the integrated terminal and run these two commands once. They apply to every repository.
git config --global user.name "Your Name"
git config --global user.email "you@example.com"Step 2: Open the Source Control view
Click the Source Control icon in the activity bar on the left (it looks like a branching line), or press Ctrl+Shift+G. Because the folder is not yet a repository, you will see an Initialize Repository button.
Step 3: Initialize the repository
Click Initialize Repository. VS Code runs git init for you and creates a hidden .git folder. The Source Control view now lists every file in your project under Changes, because nothing has been committed yet.
Step 4: Add a .gitignore
Before your first commit, create a .gitignore file so you do not commit junk like node_modules or environment secrets. Make a new file named .gitignore in the project root with these lines.
node_modules/
dist/
.env
.DS_StoreStep 5: Stage and commit
Hover over Changes and click the plus icon to stage all files, or stage individual files. Type a short message in the box at the top, such as Initial commit, then click the checkmark (Commit) button. Your first snapshot is saved.
Result
Your folder is now a git repository with a clean first commit and a .gitignore protecting it from clutter. Every future change shows up in Source Control, ready to review and commit.
Watch related tutorials
35:00
18:22
1:42:18
28:14
41:09
9:47New guides in your inbox
Fresh step-by-step how-to guides as we publish them. One email a week, no more.