How to Use Git in Visual Studio Code: A Beginner’s Guide

Visual Studio Code (VS Code) is a popular, lightweight code editor that comes with built-in Git integration, making version control seamless for developers. Whether you’re new to Git or want to streamline your workflow, VS Code offers an intuitive interface to manage your repositories.

In this post, you’ll learn how to use Git inside Visual Studio Code — from cloning a repo to committing and pushing your changes.


✅ Prerequisites

  • Git installed on your system (Download Git)
  • Visual Studio Code installed (Download VS Code)
  • A Git repository (local or remote on GitHub, GitLab, etc.)

🔹 Step 1: Open Your Project or Clone a Repository

Option A: Open an Existing Git Repo

  • Open VS Code.
  • Click File > Open Folder and select your project folder.
  • VS Code will detect the Git repository automatically.

Option B: Clone a Remote Repository

  • Open VS Code.
  • Press Ctrl+Shift+P (or Cmd+Shift+P on macOS) to open the Command Palette.
  • Type Git: Clone and select it.
  • Paste the repo URL (HTTPS or SSH).
  • Choose a local folder to clone the repo into.
  • Once cloned, VS Code will prompt you to open the new folder.

🔹 Step 2: View Git Changes

  • Click the Source Control icon on the left sidebar (or press Ctrl+Shift+G).
  • The Source Control panel shows:
    • Modified files
    • Staged files
    • Untracked files

Files with changes will be listed here, color-coded to indicate added, modified, or deleted files.


🔹 Step 3: Stage and Commit Changes

  1. Stage a file:
    Hover over the changed file and click the + icon, or right-click the file and choose Stage Changes.
  2. Stage all changes:
    Click the + icon next to Changes header.
  3. Commit your changes:
    • Enter a meaningful commit message in the message box at the top.
    • Press Ctrl+Enter or click the ✔️ checkmark icon to commit.

🔹 Step 4: Push and Pull Changes

  • Push commits to remote:
    Click the “…” menu in the Source Control panel and select Push, or use the status bar button.
  • Pull latest changes from remote:
    Select Pull from the same menu to sync your local copy.

🔹 Step 5: Branching and Merging

  • Click the current branch name in the bottom-left corner to:
    • Switch branches
    • Create new branches
    • Manage branch merges

VS Code shows branch names and offers easy commands to manage your workflow.


🔹 Step 6: Resolve Conflicts

If you encounter conflicts when pulling or merging:

  • VS Code highlights conflicting sections in files.
  • Use inline buttons like Accept Current Change or Accept Incoming Change.
  • After resolving, stage the file and commit.

🧠 Bonus Tips

  • Install the GitLens extension for enhanced Git insights and history browsing.
  • Use the Terminal inside VS Code (`Ctrl+“) to run any Git commands directly.
  • Customize Git settings in VS Code via File > Preferences > Settings and search for “Git”.

✅ Summary of Key Actions

TaskHow to Do It in VS Code
Clone a repoCommand Palette → Git: Clone
View changesSource Control panel (Ctrl+Shift+G)
Stage changesClick + icon next to files
Commit changesEnter message + click ✔️ or Ctrl+Enter
Push/PullUse Source Control menu or status bar buttons
Switch/create branchesClick branch name bottom-left
Resolve merge conflictsUse inline buttons in editor

🏁 Conclusion

Using Git inside Visual Studio Code makes version control simple and visual. Whether you prefer GUI operations or the terminal, VS Code provides powerful Git features that boost productivity and streamline collaboration.

Sharing Is Caring:

Leave a Comment