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:
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.
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:
- Code review
- Issue tracking
- Continuous integration (CI)
- Continuous delivery (CD)
- Wiki documentation
- Project management
- Permission management
- Visualizing progress
- And more…
The main remote repositories include:
GitHub (Microsoft):
- Offers code review, issue tracking, CI, and more.
- Popular among individual developers and enterprises.
- Free and paid plans available for different needs.
GitLab:
- Can be self-hosted or used as a cloud service.
- Emphasizes DevOps and CI/CD integration, providing a complete DevOps platform.
- Available in free (community edition) and paid (enterprise edition) versions.
Azure DevOps (Microsoft):
- A comprehensive DevOps platform including code management, CI/CD, and project management.
- Deep integration with Azure cloud services.
- 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:
- Git
- VS Code
- Windows Terminal (optional)
- PowerShell (optional)
- 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
andTortoiseGit
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
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.
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.
Need to Buy Related Books?
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:
Conclusion
The next chapter will explain how to integrate Git and projects using VS Code.