Git Fundamentals
Introduction to Version Control
Version control is a critical system for tracking and managing changes in software development. Git, a distributed version control system, enables developers to collaborate effectively, manage code history, and maintain project integrity.
Core Git Concepts
What is Git?
Git is a distributed version control system that allows multiple developers to work on the same project simultaneously. Unlike centralized systems, Git provides each developer with a complete local repository.
graph LR
A[Local Repository] --> B[Remote Repository]
B --> C[Collaboration]
Key Git Components
Component |
Description |
Repository |
Complete project history and metadata |
Commit |
Snapshot of project changes |
Branch |
Parallel development line |
Remote |
External repository location |
Git Installation and Configuration
To install Git on Ubuntu 22.04, use the following command:
sudo apt update
sudo apt install git
Configure your Git identity:
git config --global user.name "Your Name"
git config --global user.email "[email protected]"
Creating a Git Repository
Initialize a new repository:
mkdir my_project
cd my_project
git init
This command creates a new Git repository in the current directory, enabling version control tracking.
Basic Git Workflow
- Make changes to files
- Stage changes
- Commit changes
- Push to remote repository
## Stage specific file
git add filename.txt
## Stage all changes
git add .
## Commit changes
git commit -m "Descriptive commit message"
## Push to remote repository
git push origin main