Intro to Git: Version Control Basics
Git: Version Control Fundamentals
Git is a version control and source code management system that keeps track of every change in your code. It’s essential for both individual developers and teams.
Understanding Version Control
A version control system helps you:
- Track changes over time
- Collaborate with others
- Maintain different versions of your code
- Revert to previous states when needed
Git’s Three-Stage Workflow
Git manages your code through three main stages:
- Working Directory: Your current working files
- Staging Area: Changes marked for the next commit
- Git Directory: Repository containing the complete history
The Basic Git Workflow
Working Directory → Staging Area → Git Repository
(edit files) (git add) (git commit)
Getting Started with Git
Initial Configuration
First, set up your Git identity:
# Set your name
$ git config --global user.name 'agyago'
# Set your email
$ git config --global user.email 'agyago@test.com'
Creating a New Repository
# Create a project directory
$ mkdir project
$ cd project/
# Initialize Git repository
$ git init
# Output: Initialized empty Git repository in /home/agyago/project/
Core Git Commands
The three essential commands for daily Git usage:
git add: Stage your changesgit commit: Save staged changes to repositorygit push: Upload local commits to remote repository
Git Workflow Diagram
Repository → Clone → Working Directory
↑
Edit/Add files
|
Stage
|
Status
|
Review changes
|
Commit
↓
Git Directory
Key Concepts
- Working Directory: Contains your actual files
- Staging: Prepares changes to be included in the next commit
- Git Directory: Stores the complete project history
Remember: Git is not just a backup system—it’s a powerful tool for managing your code’s evolution over time.
$ git config --global user.name 'agyago'
$ git config --global user.email 'agyago@test.com'
$ mkdir project
$ cd project/
$ git init
Initialized empty Git repository in /home/agyago/project/