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
12:47
18:33
15:21
15:22
1:02:14
18:05