๐ Version Control Systems
Version control systems (VCS) are tools that help track changes to source code and files over time. They support team collaboration, manage change history, and maintain multiple versions of source code. There are two main types of VCS:
- Centralized VCS (CVCS): Uses a central repository, examples include Subversion (SVN), CVS.
- Distributed VCS (DVCS): Each user has a complete copy of the repository, including the entire history. The most popular example is Git.
Git is a powerful distributed version control system that allows offline work, supports fast branching and merging operations, enhancing collaboration capabilities.
๐น Installing Git
If you haven’t installed Git yet, you can download it from git-scm.com or use the following commands:
1
2
3
| sudo apt install git # Ubuntu/Debian
yum install git # CentOS/RHEL
brew install git # macOS
|
Verify Git installation:
1
2
3
4
| git --version
# output:
# git version 2.47.1.windows.1
|
๐ Basic Git Commands
Below are common Git commands, organized from basic to advanced:
Initialization & Configuration
1
| git init # Initialize Git repository
|
1
2
| git config --global user.name "Your Name" # Configure name
git config --global user.email "[email protected]" # Configure email
|
Working With Repository
1
| git clone <repo_url> # Clone a remote repository to local machine
|
1
| git status # Check file status
|
Adding & Saving Changes
1
| git add <file> # Add file to staging area
|
1
| git commit -m "Change description" # Save changes to history
|
Working With Remote Repository
1
| git remote add origin <repo_url> # Link remote repository
|
1
| git push -u origin main # Push changes to main branch
|
1
| git pull origin main # Update latest changes from remote repository
|
Working With Branches
1
| git branch new-feature # Create new branch
|
1
| git checkout new-feature # Switch to new branch
|
1
| git merge new-feature # Merge branch into current branch
|
Tracking History
1
| git log # View commit history
|
1
| git diff # Compare changes between versions
|
๐ Free Git Learning Resources
๐ Conclusion
Using Git makes source code management easier, supports effective team collaboration, and protects important project data. Understanding and mastering Git is an essential skill for every programmer.
๐ Next step: Learn about GitHub & GitLab to manage Git repositories on cloud platforms.