git-workflow
npx machina-cli add skill agenticdevops/devops-execution-engine/git-workflow --openclawFiles (1)
SKILL.md
6.8 KB
Git Workflow
Git operations and DevOps best practices.
When to Use This Skill
Use this skill when:
- Managing code changes
- Creating pull requests
- Handling releases
- Resolving conflicts
- Debugging with git history
Daily Operations
Status & Info
# Current status
git status
# Short status
git status -s
# Current branch
git branch --show-current
# Recent commits
git log --oneline -10
# What changed today
git log --oneline --since="midnight"
Sync with Remote
# Fetch updates (doesn't merge)
git fetch origin
# Pull with rebase (cleaner history)
git pull --rebase
# Pull specific branch
git pull origin main
Commit Changes
# Stage specific files
git add file1.txt file2.txt
# Stage all changes
git add -A
# Interactive staging
git add -p
# Commit with message
git commit -m "feat: add user authentication"
# Amend last commit (before push)
git commit --amend
# Amend without changing message
git commit --amend --no-edit
Branch Management
Create & Switch
# Create and switch
git checkout -b feature/new-feature
# Or modern way
git switch -c feature/new-feature
# Switch to existing
git checkout main
git switch main
# From specific commit/branch
git checkout -b hotfix/bug-123 origin/main
List Branches
# Local branches
git branch
# Remote branches
git branch -r
# All branches
git branch -a
# With last commit info
git branch -v
Delete Branches
# Delete local (merged)
git branch -d feature/old-feature
# Force delete (unmerged)
git branch -D feature/abandoned
# Delete remote
git push origin --delete feature/old-feature
# Cleanup stale remote refs
git fetch --prune
Pull Requests (GitHub CLI)
Create PR
# Push branch first
git push -u origin feature/my-feature
# Create PR
gh pr create --title "Add feature X" --body "Description here"
# Create with template
gh pr create --fill
# Draft PR
gh pr create --draft
Review PRs
# List PRs
gh pr list
# View specific PR
gh pr view 123
# Check out PR locally
gh pr checkout 123
# Diff
gh pr diff 123
Merge PRs
# Merge
gh pr merge 123
# Squash merge
gh pr merge 123 --squash
# Rebase merge
gh pr merge 123 --rebase
# Delete branch after merge
gh pr merge 123 --delete-branch
Hotfix Workflow
# 1. Create hotfix branch from main/production
git checkout main
git pull origin main
git checkout -b hotfix/critical-bug-123
# 2. Make fix
git add .
git commit -m "fix: resolve critical bug #123"
# 3. Push and create PR
git push -u origin hotfix/critical-bug-123
gh pr create --title "Hotfix: Critical bug #123" --base main
# 4. After merge, tag release
git checkout main
git pull origin main
git tag -a v1.2.1 -m "Hotfix release v1.2.1"
git push origin v1.2.1
Release Management
Tagging
# Create annotated tag
git tag -a v1.2.0 -m "Release v1.2.0"
# List tags
git tag -l
# List with pattern
git tag -l "v1.*"
# Push tags
git push origin v1.2.0
git push origin --tags # all tags
# Delete tag
git tag -d v1.2.0
git push origin --delete v1.2.0
Changelog from Commits
# Commits since last tag
git log $(git describe --tags --abbrev=0)..HEAD --oneline
# Formatted for changelog
git log $(git describe --tags --abbrev=0)..HEAD --pretty=format:"- %s"
Debugging with Git
Find Who Changed What
# Blame (who changed each line)
git blame file.txt
# Blame specific lines
git blame -L 10,20 file.txt
# Ignore whitespace
git blame -w file.txt
Find When Bug Introduced
# Binary search
git bisect start
git bisect bad HEAD
git bisect good v1.0.0
# Test each commit, mark good/bad
git bisect good # or git bisect bad
# When done
git bisect reset
Search History
# Search commit messages
git log --grep="bug fix"
# Search code changes
git log -S "function_name" --oneline
# Search with regex
git log -G "regex_pattern"
# Show what changed in commits
git log -p --grep="feature"
Undo Operations
Unstage Files
# Unstage file
git restore --staged file.txt
# Old way
git reset HEAD file.txt
Discard Changes
# Discard working directory changes
git restore file.txt
# Discard all changes
git restore .
# Old way
git checkout -- file.txt
Reset Commits
# Soft reset (keep changes staged)
git reset --soft HEAD~1
# Mixed reset (keep changes unstaged)
git reset HEAD~1
# Hard reset (discard changes - DANGEROUS)
git reset --hard HEAD~1
Revert (Safe for Shared History)
# Create new commit that undoes
git revert HEAD
# Revert specific commit
git revert abc1234
# Revert without auto-commit
git revert --no-commit abc1234
Stashing
# Stash changes
git stash
# Stash with message
git stash push -m "WIP: feature X"
# List stashes
git stash list
# Apply latest stash
git stash pop
# Apply specific stash
git stash apply stash@{1}
# Drop stash
git stash drop stash@{0}
Merge & Rebase
Merge
# Merge branch into current
git merge feature/new-feature
# Merge with commit (no fast-forward)
git merge --no-ff feature/new-feature
# Abort merge
git merge --abort
Rebase
# Rebase current onto main
git rebase main
# Interactive rebase (edit history)
git rebase -i HEAD~3
# Continue after resolving conflicts
git rebase --continue
# Abort rebase
git rebase --abort
Conflict Resolution
# See conflicting files
git status
# After editing conflicts
git add resolved-file.txt
git rebase --continue # or git merge --continue
Configuration
# User setup
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
# Default branch
git config --global init.defaultBranch main
# Useful aliases
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.st status
git config --global alias.lg "log --oneline --graph --all"
Quick Reference
# Morning sync
git fetch --all && git pull --rebase
# Feature branch workflow
git checkout -b feature/X && [make changes] && git add . && git commit -m "feat: X" && git push -u origin feature/X && gh pr create
# Quick fixup
git add . && git commit --amend --no-edit && git push --force-with-lease
# Clean merged branches
git branch --merged | grep -v "main\|master" | xargs git branch -d
Related Skills
- terraform-workflow: For IaC version control
- k8s-deploy: For deployment workflows
- incident-response: For hotfix procedures
Source
git clone https://github.com/agenticdevops/devops-execution-engine/blob/main/skills/git-workflow/SKILL.mdView on GitHub Overview
This skill covers core git operations, branching patterns, PRs, hotfix workflows, and release management. It pairs daily git commands with DevOps practices to help you manage code changes, resolve conflicts, and deliver releases efficiently.
How This Skill Works
It documents practical workflows built around core git commands and GitHub CLI, including status checks, syncing with remotes, creating and managing branches, and implementing hotfix and release processes. The SKILL.md examples—status, fetch, pull --rebase, PR creation, merging, and tagging—guide hands-on execution.
When to Use It
- Managing code changes
- Creating pull requests
- Handling releases
- Resolving conflicts
- Debugging with git history
Quick Start
- Step 1: Create and switch to a feature branch (git checkout -b feature/feature-name)
- Step 2: Stage, commit, and push changes (git add -A; git commit -m '...' ; git push -u origin feature/feature-name)
- Step 3: Open a PR and merge after review (gh pr create ...; gh pr merge ... )
Best Practices
- Keep feature branches short-lived and focused.
- Fetch and rebase to maintain a clean history before merging.
- Use pull requests with reviews (GitHub CLI) for gatekeeping.
- Tag releases after merges and push tags to origin.
- Use git blame and git bisect to locate and diagnose bugs.
Example Use Cases
- Hotfix workflow to patch a production bug and release a patch version
- Tagging releases (e.g., v1.2.0) and pushing tags to origin
- Creating, reviewing, and merging a feature branch via PR
- Deleting stale or merged remote branches to keep refs clean
- Using git bisect and blame to locate when a bug was introduced
Frequently Asked Questions
Add this skill to your agents