Git Basics and Setup
Introduction to Version Control System
Version control system (VCS) is a critical tool in modern software development, enabling developers to track changes, collaborate effectively, and manage project history. Git stands out as the most popular distributed version control system, offering robust features for tracking code modifications.
Git Installation on Ubuntu 22.04
To install Git on Ubuntu, use the following command:
sudo apt update
sudo apt install git
Verify the installation:
git --version
Git Configuration
Configure your Git identity with global settings:
git config --global user.name "Your Name"
git config --global user.email "[email protected]"
Configuration Levels
Level |
Scope |
Command |
Global |
All repositories |
git config --global |
System |
Entire machine |
git config --system |
Local |
Current repository |
git config --local |
Basic Git Workflow
graph LR
A[Working Directory] --> B[Staging Area]
B --> C[Local Repository]
C --> D[Remote Repository]
Creating a New Repository
Initialize a new Git repository:
mkdir my-project
cd my-project
git init
Create your first commit:
touch README.md
git add README.md
git commit -m "Initial commit"
Understanding Git Concepts
Git uses a snapshot-based approach to track changes, storing complete file versions rather than just differences. Each commit represents a specific point in project history, allowing easy rollback and version tracking.