Git & GitHub Commands Cheat Sheet for DevOps
Engineers
Basic Git Setup
• git config --global [Link] "Your Name" - Set global username
• git config --global [Link] "your@[Link]" - Set global email
• git config --list - Verify configuration
Repository Setup
• git init - Initialize a new repo
• git clone - Clone a repo from GitHub
• git remote add origin - Add a remote origin
• git remote -v - View remote repos
Staging & Committing
• git status - Check file status
• git add - Stage file
• git add . - Stage all files
• git commit -m "message" - Commit staged changes
• git log - View commit history
• git diff - Show unstaged changes
• git diff --staged - Show staged changes
Branching & Merging
• git branch - List branches
• git branch - Create new branch
• git checkout - Switch to branch
• git checkout -b - Create + switch
• git merge - Merge branch into current
• git branch -d - Delete branch
• git log --oneline --graph --all - Visualize branches
Pushing & Pulling (GitHub)
• git push origin - Push branch to GitHub
• git push -u origin - Push and set upstream
• git pull origin - Pull latest changes
• git fetch - Download changes without merging
• git pull - Fetch + merge
Undo & Fix
• git restore - Discard unstaged changes
• git reset - Unstage file
• git reset --hard HEAD - Reset working dir to last commit
• git checkout - Switch to old commit
• git revert - Undo commit by creating new one
Collaboration & PR Workflow
• git fetch origin - Fetch remote branches
• git checkout -b feature-x origin/feature-x - Work on remote branch
• git rebase main - Rebase with main branch
• git stash - Save changes temporarily
• git stash pop - Apply stashed changes
Advanced (Useful for DevOps Automation)
• git tag - Create tag (release versions)
• git show - Show tag details
• git push origin - Push a tag to GitHub
• git push origin --tags - Push all tags
• git cherry-pick - Apply specific commit
• git clean -fd - Remove untracked files
• git reflog - Show history of all actions