iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
🌏

Essential Git Knowledge for Beginners Who Just Discovered the Importance of GitHub

に公開

On GitHub, people and companies from all over the world publish source code, allowing others to make improvements or report bugs. The tool used for this is Git. However, Git itself is not directly related to GitHub and can be used as a standalone tool. Because it is often explained in conjunction with GitHub (I also originally thought Git was created for GitHub), it can be confusing for beginners. Therefore, this article will provide only the bare minimum explanation.

What is Git?

It is a version control system.

What is a version control system?

A version control system records the change history of programs and similar files. When you fix a bug, add a feature, or simply correct a typo, you can record the changes (a commit) and see how the code has changed over time. This allows you to look through the change history when a bug occurs to figure out which change caused it, or more directly, to revert to a previous version to investigate when the bug was introduced.

Branches

In Git, it is common to create something called a branch to perform development. For example, when you want to add a new feature, you create a branch named new-feature, record the code changes there, and once the new feature is complete, merge it into the main line (merge).
Why do we do this? Because if a bug is found in the original code while developing a new feature, you can quickly return to the main line, fix the bug, and then continue developing the new feature. Furthermore, when conducting social coding on GitHub or developing in a team environment, if everyone adds changes directly to the same main line, problems can arise where bugs are introduced because people are unaware of changes made by others. Therefore, it is standard practice to first create a personal branch, and once the development team leader reviews it and determines it is acceptable, it is merged into the main line.

How to use Git

Installing Git

Since there are many configuration settings involved, I will refer you to the following page.
Steps to install Git on Windows (Updated December 2022)

Basic Git Operations

I will also refer you to this for the basics.
Git Basics: From Initialization to Commit - Qiita

GUI Tools

Git itself only supports command-line operations, but this can make it difficult to see change histories or how branches diverge. Therefore, I recommend using a GUI tool. I personally use SourceTree, which visualizes change histories and branches as shown below. It also makes basic operations like creating branches simple (for complex tasks, you can click the 'Terminal' button in the upper right corner).

image.png

It also makes it easy to do things like committing only part of the changes within a single file.

Again, I will leave the installation instructions to others.
【For Beginners】 An easy-to-understand guide on how to use SourceTree! | mteam

Conclusion

Since Git is deeply related to GitHub, you will need to learn how to upload source code to GitHub, how to send a Pull Request (requesting that your changes be reflected) to another person's repository (a collection of program source code, etc.), and various other Git features. However, there are countless tutorial sites available for these topics, and if you know what is written in this article, you should be able to master them quickly by searching.

In fact, if we start discussing the details—like how frequently you should commit, the formatting for commit messages, or how to name branches—the topic would never end and wouldn't fit into a single article. Please search for and learn about the details of Git as you need them.

Discussion