Let's operate Git with VS Code!
table of contents
Nice to meet you, I'm Nagato from the System Development Department!
This time, I will explain how to operate the version control system "Git" from vscode.
We will explain six basic Git operations in the following order.
・Branch switching & creation
・Commit & push
・ Pull
・ Merge (conflict resolution)
Switching & creating branches
There is a field at the bottom left of the screen where the branch name is written.
Clicking there will display a dialog at the top where you can create and switch branches.
"Create new branch..." allows you to create a child branch of the current branch.
Enter the name and press Enter to complete!
If you look at the bottom left column, you can see that you have switched to the branch you created earlier.
At this stage, we are only creating a local branch, so click the Publish button next to it to create a remote branch.
commit & push
Next, let's commit and push.
Edit the file a little. Then, there is a tab displayed as ① in the sidebar.
This shows that there is one edited file.
tab and click the + next to the edited file name.
You can then move to "Staged Changes".
You can only commit files that have been moved to this "staged changes", so
you can distinguish between what you want to commit and what you don't want to commit yet.
Enter a comment in the text box and click check to complete the commit.
Finally, let's do a pull.
Simply click on the part marked 1↑ at the bottom left to complete the pull.
pull
just click on the part marked 1↓,
just like the previous push If there are any files that have been changed or added to the remote branch, a number of 1 or higher will be displayed here, so check them carefully.
Merge (conflict resolution)
Finally, let's merge and resolve conflicts.
Move to the tab on the left and click on the "..." part.
You can also perform operations such as commit, pull, and push from here.
This time, select "Merge Branch..." from "Branch".
A dialog will then appear where you can select the branch you want to merge.
After selecting a branch, merging will occur automatically.
When a conflict occurs, the current changes (changes on a different branch) and changes on the input side (changes on the merge branch) are color-coded like this.
"Import current changes | Import changes from input side | Import both changes | Compare changes"
above the conflicting , and you can select it.
This time, select "Import both changes."
The changes were applied and the conflict was successfully resolved.
Once you commit and pull, the reflection on the remote branch is complete.
summary
You can open the console with Ctrl+Alt+@, so you can still perform the same operations as before using git commands.
However, managing git using VScode is intuitive, easy to understand, and smooth, so please give it a try.
lastly
I have opened the system development service site "SEKARAKU Lab" to which I belong.
Beyond is a one-stop service for everything from server design and construction to operation, so if you have any trouble with server-side development, please feel free to contact us.
SEKARAKU Lab: [https://sekarakulab.beyondjapan.com/](https://sekarakulab.beyondjapan.com/)