Let's operate Git with VScode!

Hello, I'm Nagato from the Systems Development Department!
This time, I'll be explaining how to use the version control system "Git" from VS Code.

We will explain the six basic Git operations in the following order

- Switching branches, creating branches
, committing, pushing
, pulling
, and merging (resolving conflicts)

Switching and creating branches

In the lower left corner of the screen, there is a field displaying the branch name.

Clicking there will bring up a dialog box at the top, allowing you to create and switch branches.
You can create a child branch of the current branch by clicking "Create New Branch...".

Enter a name and press Enter to complete!

If you look at the lower left corner, you can see that you have switched to the branch you just created.
At this stage, only a local branch has been created, so let's click the publish button next to it to create a remote branch.

Commit and push

Next, let's commit and push.
We'll make a small edit to the file. You'll then see a tab labeled ① in the sidebar.
This indicates that there is one edited file.
Navigate to the tab and click the + next to the name of the edited file.

This allows you to move the changes to "Staged Changes."
Only files that have been moved to "Staged Changes" can be committed,
making it easier to distinguish between files to commit and those to wait.

Enter a comment in the text box and click the check box to complete the commit

Finally, let's do a pull.
Simply click on the "1↑" in the bottom left corner to complete the pull.

pull

Pulling is just as easy as pushing;
simply click on the area marked "1↓".
If there are any changes or additions to files in the remote branch, a number greater than 1 will appear here, so be sure to check it regularly.

Merge (conflict resolution)

Finally, let's perform a merge and resolve conflicts.
Go to the tab on the left and click on the "..." icon.
You can also perform operations such as commit, pull, and push from here.
This time, let's select "Merge Branch..." from "Branches".

A dialog will appear, allowing you to select the branch you want to merge

After selecting a branch, the merge will be performed automatically.
If a conflict occurs, the current changes (changes from the different branch) and the input changes (changes from the merged branch) will be color-coded as shown.
Above the conflicting changes, you
see "Incorporate current changes | Incorporate input changes | Incorporate both changes | Compare changes"
and you can select one of them.
In this case, we will select "Incorporate both changes".

The changes have been applied and the conflict has been successfully resolved.
Committing and pulling will complete the process of reflecting the changes to the remote branch.

summary

You can open the console with Ctrl+Alt+@ and perform the same operations using git commands.
However, managing Git in VS Code is more intuitive, easier to understand, and smoother, so please give it a try.

lastly

I have launched "SEKARAKU Lab," a service site for the system development company I belong to.
Beyond offers a one-stop service for everything from server design and construction to operation, so please feel free to contact us if you have any problems with server-side development.
SEKARAKU Lab:[https://sekarakulab.beyondjapan.com/](https://sekarakulab.beyondjapan.com/)

If you found this article helpful,please give it a "Like"!
1
Loading...
1 vote, average: 1.00 / 11
13,176
X Facebook Hatena Bookmark pocket

The person who wrote this article

About the author

Nagato Masateru

I joined the company as a new graduate in April 2020. I'm Nagato, and I belong to the Systems Development Department.
I mainly develop web systems and game APIs using PHP.
Qualifications: PHP7 Certified Beginner