Git Version Control Basics
Understanding Version Control Systems
Version control is a critical tool in software development for tracking and managing code changes. Git, a distributed version control system, enables developers to collaborate efficiently, maintain code history, and manage complex software projects.
Core Concepts of Git
Git fundamentals revolve around three primary components:
Component |
Description |
Purpose |
Repository |
Project storage location |
Stores all project files and version history |
Commit |
Snapshot of project changes |
Records specific modifications at a point in time |
Branch |
Independent line of development |
Allows parallel work on different features |
Setting Up Git on Ubuntu 22.04
## Install Git
sudo apt update
sudo apt install git
## Configure user identity
git config --global user.name "Your Name"
git config --global user.email "[email protected]"
Creating and Initializing a Repository
## Create a new project directory
mkdir my-project
cd my-project
## Initialize a new Git repository
git init
Basic Git Workflow
graph LR
A[Working Directory] --> B[Staging Area]
B --> C[Local Repository]
C --> D[Remote Repository]
Essential Git Commands
## Check repository status
git status
## Stage changes
git add filename.txt
git add .
## Commit changes
git commit -m "Descriptive commit message"
## View commit history
git log
Understanding Git's Version Control Mechanism
Git tracks changes through a series of snapshots, not file differences. Each commit represents a complete state of the project, enabling efficient version management and rollback capabilities.