πŸš€ Git Cheatsheet for DevOps & Cloud Engineers

Master Git with this command-by-command reference for real-world cloud and infrastructure workflows. Stay version-controlled, clean, and collaborative.

πŸ”§ Git Basics

git init                     # Initialize a local repo

# Clone from remote
git clone <url>             # Clone remote repo

# Stage & commit
git add .                   # Stage all changes
git commit -m "message"     # Commit with message

# Push / Pull
git push                    # Push to remote
git pull                    # Pull from remote

# Check status
git status                  # Show working tree status

# Log
git log                     # View commit history

🌿 Branching & Merging

git branch                  # List branches
git branch <name>           # Create new branch
git checkout <name>         # Switch to branch
git switch <name>           # Modern switch

git merge <branch>          # Merge a branch into current

# Graph view
git log --oneline --graph --all

πŸ’ Cherry Pick

git cherry-pick <commit>    # Apply commit from another branch

🏷️ Tagging

git tag                     # List tags
git tag v1.0                # Create lightweight tag
git tag -a v1.0 -m "msg"    # Annotated tag
git push origin v1.0       # Push tag to remote

🌍 Remote & Tracking

git remote -v               # Show remotes
git remote add origin <url># Add new remote

git fetch                   # Fetch changes without merge
git pull --rebase           # Pull with rebase

πŸ›  DevOps-Specific Git Commands

# Git stash before switching
git stash                  # Save uncommitted changes
git stash pop              # Reapply stashed changes

# Clean working tree
git clean -fd              # Remove untracked files & dirs

git reset --hard HEAD      # Reset all local changes

# Bisect to find breaking commit
git bisect start           # Begin binary search
git bisect bad             # Mark current as bad
git bisect good <commit>   # Mark known good commit

git reflog                 # History of HEAD movements

βœ… Git Attributes & Ignore

# Git ignore
nano .gitignore            # Add files to ignore

# Git attributes
nano .gitattributes        # Define merge/diff rules, LFS etc.

πŸ“Š Git Graph Summary

git log --all --decorate --oneline --graph

🌐 Hosting on GitHub/GitLab

git remote add origin git@github.com:username/repo.git
git push -u origin main    # Push main branch

✨ Built for modern Git workflows. Don’t use git pull --rebase blindly unless you know what you’re doing.

🧠 Visit the GitHub Page or star the GitHub Repo to support this project.