Git in Visual Studio Code
This walk through will guide you through using the Git graphical user interface (GUI) tools in Visual Studio Code. You'll learn how to initialize a Git repository, make commits, create branches, and merge branches, all using the visual tools in Visual Studio Code.
Step 1: Install Visual Studio Code
First, you need to ensure that Visual Studio Code is installed on your computer. You can download it from the official website.
Step 2: Open a New Folder in Visual Studio Code
Open Visual Studio Code and select File > Open...
from the menu. Navigate to the folder you want to use for this walk through. If you don't have a folder ready, you can create a new one.
Step 3: Initialize a Git Repository
Open the Source Control view by clicking on the Source Control icon in the Activity Bar on the side of the window. Click on Initialize Repository
to create a new Git repository in your folder.
Step 4: Create a File and Make an Initial Commit
Create a new file in your folder by selecting File > New File
from the menu. You can enter some text in the file if you want. Save the file by selecting File > Save
from the menu.
In the Source Control view, you'll see your new file listed under Changes. Click the +
button next to the file to stage the changes. Enter a commit message in the text box at the top of the Source Control view and press Ctrl+Enter
(or Cmd+Enter
on a Mac) to commit your changes.
Bonus: Branching and Merging
Now that you've made an initial commit, you can try out branching and merging. Here are the steps:
-
Create a new branch. In the Source Control view, click on the branch name at the bottom of the window (it will say
main
ormaster
). In the dropdown that appears, selectCreate new branch...
and enter a name for your new branch. -
Make some changes and commit them. Edit your file or create a new one, then stage and commit the changes just like you did for the initial commit.
-
Switch back to the
main
branch. Click on the branch name at the bottom of the window and selectmain
from the dropdown. -
Merge your branch into
main
. Click on the ellipsis (...
) at the top of the Source Control view to open the More Actions menu. SelectMerge Branch...
and then select the name of your branch. -
Resolve any merge conflicts. If there are any conflicts, Visual Studio Code will highlight these in the editor. You can choose which version to keep for each conflict.
-
Commit the merge. Once you've resolved all conflicts, stage the changes and commit them.
Congratulations! You've now practiced using the Git GUI tools in Visual Studio Code.