0% found this document useful (0 votes)
163 views

Git With Vscode

This document provides an overview of using Git with Visual Studio Code, including initializing a Git repository, staging and committing files, creating and switching branches, comparing file differences, merging branches, and publishing a repository to GitHub. Key steps include initializing a local Git repo, renaming the default branch before first commit, staging files for commits, creating a new branch to experiment without affecting the main branch, merging branches to bring changes into the main codebase, and adding a remote to push the local repo to GitHub.

Uploaded by

James Clark
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
163 views

Git With Vscode

This document provides an overview of using Git with Visual Studio Code, including initializing a Git repository, staging and committing files, creating and switching branches, comparing file differences, merging branches, and publishing a repository to GitHub. Key steps include initializing a local Git repo, renaming the default branch before first commit, staging files for commits, creating a new branch to experiment without affecting the main branch, merging branches to bring changes into the main codebase, and adding a remote to push the local repo to GitHub.

Uploaded by

James Clark
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

notes.

md 8/3/2023

Using Git with Visual Studio Code


Highlights
1. Intro
2. Initialize repository
3. Rename branch
4. Staging files
5. Committing files
6. Create new branch
7. Gutter overview
8. Comparing files / inline view
9. Merging branches
10. Publish to Github
11. Clone repository
1. Intro
Git is a VCS used to keep track of the changes in files and folders over time. While Github is a service for
hosting git repos. While vscode makes working with git and github easy.

2. Initialize a repo
This assumes you already have git installed. To install git, download from: download git.
To use git, you must first initialize a 'git repo' inside the target folder. This is like installing git in the folder:
Click on the git icon on the activity bar.
And click the 'Initialize Repository' button.

The default branch is named 'main'. You can change it before making your first commit.

1/8
notes.md 8/3/2023

3. Rename the default branch


NB: It is important to do this making the first commit.
. Open the command pallete(cmd|chtr + shift + p)
. Type: rename or Git rename branch.
. Enter the new name and hit enter

4. Staging and making commits


Before making the first commit, you will see letter 'U'(meaning untracked) appear next to to the file(s) in
your project.
For already tracked files, 'M' (modified) will show.

Staging files
2/8
notes.md 8/3/2023

This is adding one or more files to the staging/index area for the next commit. You can stage all new and
modified files and folders with the '+' on the Changes tab, or stage individual file with the '+' on each of the
files.

Making a commit
After staging, you can not commit the state to the repo.
Add a commit message
Hit the commit button.

3/8
notes.md 8/3/2023

5. Branching
All the commits made so far are all on the main/default branch: the master branch.
If you need to experiment on a feature on the side and does not want this to impact your main branch in any
way, you will create another branch.
Creating a branch
ctrl|cmd + shift + p to open the command pallete
type 'create branch' and hit enter
type the branch and hit enter

Diffing
Diffing is checking the difference in the content of a file for two different commmits. You will usually require
to install a third-party tool for this, it is now built into vscode.
Simply select a the target file in the commit history:
4/8
notes.md 8/3/2023

Inline Diffing
Instead of showing the different states in two separate windows, you may want to see them in a window.

Switching to the master branch


To switch between branches, simply click on the current branch name at the bottom of vscode. This pops
up the command pallete, displaying the available branches. Then just select the target branch.

5/8
notes.md 8/3/2023

Merging branches
Assuming you are okay with the experimental feature and wants to bring it into the main project, then you
will need to merge the branches.
To merge the new-feature branch with the master branch,first make sure you are the on the destination
branch, which is the master branch:
While on the master branch, click the 3 dots menu in the git tab
Select branches, then merge branch
Then select the target branch.

6/8
notes.md 8/3/2023

6. Pushing to Github
To push your code to github, follow these steps:
Create a repo on github where you want to push the code to, either a public or a private repo.
Copy the URL.
In vscode, open the command pallete and type: Git: Add Remote.
Paste the url and hit enter.
Git it a name and hit enter.
Now switch to the git tab on the activity bar and push.
7/8
notes.md 8/3/2023

8/8

You might also like