This project documents how to work with Git on VS Code.
- Check that
.git
is auto-created in the project folder by VS Code (view in File Explorer).
If.git
is not found, you can initialize Git for the project in 2 ways:- To get VS Code to automatically initialize Git in all projects, enable Git in VS Code settings. For VS Code 2019 and above, this should already be done (unless the user changed it).
To enable Git in VS Code: Go to File > Preferences > Settings. Type "Git: Enabled" in the search bar. Make sure that the box is ticked. - If you don't want to automatically initialize Git in all projects, and only for one project, do the following:
-
Type in terminal (within the project folder)
git --version
to check if Git is installed.
If there is an outputgit version ...
, it's already installed. If not, download Git. -
Next, update Git config with name and email (skip if already done) by typing in the Terminal:
git config --global user.name "Your Name" git config --global user.email "Your Email"
-
To initialize the Git repository, go to the Source Control tab (
Ctrl+Shift+G
) and clickInitialize Repository
or typegit init {project-name}
in the Terminal.
-
- To get VS Code to automatically initialize Git in all projects, enable Git in VS Code settings. For VS Code 2019 and above, this should already be done (unless the user changed it).
- With this Git repository, you can use the Git features on VS Code (such as branching, commiting changes). On VS Code, this is called Version/Source Control.
To see details of your current repository changes, select the Source Control icon in the Activity Bar on the left or press Ctrl+Shift+G
.
- After saving the file, stage changes by hovering over the file in the panel and click the
+
symbol- It is possible to skip this step and commit unstaged changes, but VS Code will show a warning popup.
- To commit changes, click the tick symbol at the top of the panel or press
Ctrl+Enter
. - To push local changes to remote repository (on GitHub), type
git push
in the Terminal (in your project folder).
To undo your last commit, use the command Git: Undo Last Commit
in the Command Palette (Ctrl+Shift+P
)
or click the 3 dot menu > Commit > Undo Last Commit.
- To pull changes from remote (on GitHub server) and update the local repository, go to the Source Control tab > three dot menu > Pull.
Alternatively, typegit pull
in the Terminal (in your project folder).
To visualise Git History (seeing the details of each commit and history of a file), there are 2 methods:
- Go to the File Explorer in VS Code (select the Explorer icon in the Activity Bar on the left or press
Ctrl+Shift+E
).
At the bottom of the panel, click the Timeline tab. - use the Git History Extension from Don Jayamanne
To create branches, these are 2 methods:
- In the Command Palette (
Ctrl+Shift+P
), use the commandGit: Create Branch
- Click the 3 dot menu > Branch > Create New Branch
This content was initially contributed by me (mandychew) to chewern/react-vscode-git.