mirror of
https://github.com/thecyberlearn/devops-notes.git
synced 2026-08-18 06:32:51 +00:00
1.7 KiB
1.7 KiB
Git – Basics for DevOps (Day 8)
What is Git?
Git is a version control system. It helps you track changes in code and collaborate safely.
DevOps engineers use Git DAILY.
Why Git is Important for DevOps?
- Track code changes
- Collaborate with teams
- Rollback broken deployments
- CI/CD depends on Git
Install Git
git --version
If not installed:
sudo apt install git
Configure Git (One-time Setup)
git config --global user.name "Your Name"
git config --global user.email "your@email.com"
Check config:
git config --list
Create a Git Repository
mkdir devops-project
cd devops-project
git init
Git Workflow (Basic)
- Modify files
- Stage changes
- Commit changes
Check Repository Status
git status
Add Files to Staging
git add file.txt
Add all files:
git add .
Commit Changes
git commit -m "Initial commit"
View Commit History
git log
Short view:
git log --oneline
Check File Differences
git diff
Undo Changes (Basic)
Undo unstaged changes:
git checkout -- file.txt
Real DevOps Scenario
Problem: New code broke production
Solution:
- Check commit history
- Roll back to stable commit
Git saves lives in production.
Common Mistakes
- Committing without message
- Forgetting git add
- Working directly on main branch
DevOps Rule
✅ Commit small changes
❌ Commit everything at once
Summary
Today I learned Git basics: init, add, commit, status, and log. These are core DevOps skills.