Git With Vscode
Git With Vscode
md 8/3/2023
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
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.
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