這是一張有關標題為 What is Git and Version Control? 的圖片

What is Git and Version Control?

An introduction to Git and an explanation of modern code management.

Introduction

This Git tutorial series will focus on the operation, integration, and project management using VS Code and Git.

What is Version Control?

Version control is used to track differences and changes in files over time, allowing storage and the ability to revert to specific versions.

Tools like Google Sheets and Microsoft 365 (Word, PowerPoint, Excel) offer historical version tracking:

Google Docs - View Version History Word (Microsoft 365) - Version History

With software-provided history tracking, there’s no need to duplicate files for backups, avoiding the creation of multiple copies.

Version control for text files can also compare differences between file versions. For example, it can show what changes were made from version A to version B in a file like test.txt. This is the purpose of version control.

To manage files such as text files (txt, c, py, js, md, etc.), graphics files (psd, ai), and simulation files, common industry-standard software includes Git and Subversion (SVN).

Both are open-source and free, installable on personal or company computers for managing files and projects.

What is Git?

Git is a distributed version control system (VCM).

Each member can clone the entire code from a remote repository (remote repo) to their local machine (local repo).

After cloning, each member’s local machine has its own copy for management.

If member A makes changes, they can push them to the remote repository.

Member B, who cloned the repo before A’s changes, may face conflicts (conflicts) in the same file.

B then needs to communicate with A to merge the differences or rebase.

For example, the open-source software AdGuardHome shows how developers open new branches for each version, with multiple users committing code.

Bug fixes and new feature branches are created and eventually merged by the lead developer.

Open-source AdGuardHome GitGraph

What is a Remote Repository?

After initializing a new repo locally, its contents can be pushed to a remote repository.

A remote repository’s primary function is to store code on a network server.

It may offer additional features such as:

  1. Code review
  2. Issue tracking
  3. Continuous integration (CI)
  4. Continuous delivery (CD)
  5. Wiki documentation
  6. Project management
  7. Permission management
  8. Visualizing progress
  9. And more…

The main remote repositories include:

  • GitHub (Microsoft):

    1. Offers code review, issue tracking, CI, and more.
    2. Popular among individual developers and enterprises.
    3. Free and paid plans available for different needs.
  • GitLab:

    1. Can be self-hosted or used as a cloud service.
    2. Emphasizes DevOps and CI/CD integration, providing a complete DevOps platform.
    3. Available in free (community edition) and paid (enterprise edition) versions.
  • Azure DevOps (Microsoft):

    1. A comprehensive DevOps platform including code management, CI/CD, and project management.
    2. Deep integration with Azure cloud services.
    3. Free and paid plans, suitable for enterprises and teams.

These platforms offer different service levels based on user count and payment plans.

For individual developers, GitHub is the most commonly used remote repository.

Medium and large enterprises often prefer self-hosting GitLab on internal servers to avoid placing code on GitHub.

Some foreign enterprises use Azure DevOps for code management and agile development due to its extensive DevOps capabilities.

Getting Started with Git

Choosing Command Line Interface or Graphical Interface?

Before using Git, a good IDE is essential.

Traditionally, IDEs use cmd + vim/nano text editors. Commands are input line by line through the command prompt.

When encountering file conflicts during git merge, the conflicted code must be found, edited, saved, and added using commands before committing.

In contrast, graphical interfaces (GUIs) simplify these complex command inputs. Issues can be resolved through clicks.

Most of my operations are done through the GUI for its intuitiveness and ease of use. However, certain operations may be faster with command mode.

I recommend familiarizing yourself with both methods for flexible Git usage.

Install the following on your computer:

  1. Git
  2. VS Code
  3. Windows Terminal (optional)
  4. PowerShell (optional)
  5. Clink (optional)

Refer to Awesome Windows - Essential Productivity Software Installation and Guide for detailed installation steps.

I started learning Git using GitHub.

GitHub offers GitHub Desktop, which lacks many important features and is not recommended.

Other GUIs like SourceTree and TortoiseGit are officially recommended by Git, but they don’t match VS Code’s extensibility, so they are also not recommended.

Registering on GitHub

Sign up on GitHub to get free space for code storage.

  • Unlimited public/private repositories
  • Automatic security and version updates
  • 2,000 minutes of CI/CD per month
  • Free for public repositories
  • 500 MB package storage
  • Free for public repositories
  • Issues and projects
  • Community support GitHub Copilot access

Perfect for hosting tech blogs or personal code.

For sign-up methods, follow the official step-by-step instructions. It’s straightforward.

Misconceptions About Using Git

  1. Fear of Using Git

    Anything can be Git-managed as long as files are under 100 MB (rule of thumb). Not just code, but .md or image files can also be tracked.

  2. Git is Too Complex and Difficult to Learn

    Online comparisons often portray Git as complex compared to SVN.

    In reality, for first-time Git users, the basic operation is simply: git commit with a simple description. Over time, you’ll become familiar with other operations like merging or rebasing branches.

    If you worry about mistakes, create a new branch (e.g., TEST) for operations. Once verified, rename TEST to the main branch after deleting the original branch. This minimizes errors. If issues arise during merge, simply delete the TEST branch.

No need! (But if you prefer paper books, go ahead.)

With abundant online resources, you can easily look up commands.

Free resources, including official eBooks like Pro Git book, are available.

For quicker answers, asking ChatGPT might be more efficient.

Therefore, learning Git through books is unnecessary.

Recommended learning resources include:

  1. Pro Git book
  2. Git Branching
  3. Git Tutorial (w3schools)

Conclusion

The next chapter will explain how to integrate Git and projects using VS Code.

References

  1. Git - About Version Control
  2. Version Control - Wikipedia
  3. What is Version Control? | Microsoft Learn
  4. What is Git? | Microsoft Learn
Theme Stack designed by Jimmy