Git Basics
Introduction to Version Control System
Git is a distributed version control system designed to handle everything from small to very large projects with speed and efficiency. As a version control system, Git helps developers track and manage code changes, collaborate with team members, and maintain project history.
Core Concepts of Git
Repository
A Git repository is a storage location where project files and their entire version history are kept. Repositories can be local or remote.
graph LR
A[Local Repository] <--> B[Remote Repository]
A --> C[Commit History]
B --> D[Shared Codebase]
Basic Git Operations
Operation |
Command |
Description |
Initialize |
git init |
Create a new local repository |
Clone |
git clone |
Copy a remote repository |
Add |
git add |
Stage changes for commit |
Commit |
git commit |
Save staged changes |
Status |
git status |
Check repository state |
Practical Example: Setting Up a Git Repository
## Create a new directory
mkdir my_project
cd my_project
## Initialize a new Git repository
git init
## Configure user information
git config --global user.name "Your Name"
git config --global user.email "[email protected]"
## Create a sample file
echo "## My First Project" > README.md
## Stage and commit the file
git add README.md
git commit -m "Initial project setup"
Understanding Git's Working Directory
Git manages three primary areas:
- Working Directory: Where files are modified
- Staging Area: Prepared changes ready for commit
- Repository: Permanent code history storage
This structure enables precise code tracking and version management across software development projects.