Guide for Git operations including commits, branches, rebasing, conflict resolution, and following Git best practices and conventional commits
Provides Git best practices for commits, branches, and workflows. Activates during Git operations to guide conventional commits, conflict resolution, rebasing, and repository management.
/plugin marketplace add vinnie357/claude-skills/plugin install core@vinnie357This skill inherits all available tools. When active, it can use any tool Claude has access to.
This skill activates when performing Git operations, managing repositories, resolving conflicts, or following Git workflows and conventions.
Activate when:
Follow the Conventional Commits specification:
<type>(<scope>): <subject>
<body>
<footer>
Types:
feat: New featurefix: Bug fixdocs: Documentation changesstyle: Code style changes (formatting, missing semicolons, etc.)refactor: Code refactoring without changing behaviorperf: Performance improvementstest: Adding or updating testsbuild: Changes to build system or dependenciesci: CI/CD configuration changeschore: Other changes that don't modify src or test filesrevert: Revert a previous commitExamples:
feat(auth): add JWT authentication
Implement JWT-based authentication with refresh tokens.
- Add JWT generation and validation
- Implement refresh token rotation
- Add authentication middleware
Closes #123
fix(api): handle null values in user response
Previously, null email addresses would cause the API to crash.
Now returns empty string for null emails.
Fixes #456
docs: update installation instructions
Add section on environment variable configuration.
test(user): add tests for email validation
refactor(database): simplify query builder
perf(api): add caching for user endpoints
Reduces response time by 40% for user list endpoint.
Subject line (first line):
Body:
Footer:
feat(api): add user search endpoint
Implement full-text search across user names and emails using
PostgreSQL's full-text search capabilities. Search results are
ranked by relevance.
Performance tested with 1M users - average response time < 100ms.
BREAKING CHANGE: API now requires PostgreSQL 12+
Closes #789
Co-authored-by: Jane Doe <jane@example.com>
Use descriptive, hierarchical branch names:
<type>/<short-description>
<type>/<issue-number>-<short-description>
Examples:
feature/user-authentication
feature/123-add-search
fix/456-null-pointer-error
bugfix/password-reset-email
hotfix/critical-security-patch
refactor/database-queries
docs/api-documentation
chore/update-dependencies
# Create and switch to new branch
git checkout -b feature/new-feature
# Switch to existing branch
git checkout main
git switch main # Modern alternative
# Create branch from specific commit
git checkout -b hotfix/bug origin/main
# List branches
git branch # Local branches
git branch -r # Remote branches
git branch -a # All branches
git branch -v # With last commit
# Delete local branch
git branch -d feature/completed-feature
# Force delete unmerged branch
git branch -D feature/abandoned-feature
# Delete remote branch
git push origin --delete feature/old-feature
# Stage specific files
git add file1.ex file2.ex
# Stage all changes
git add .
git add -A
# Stage parts of a file (interactive)
git add -p file.ex
# Unstage files
git restore --staged file.ex
git reset HEAD file.ex # Old syntax
# Commit staged changes
git commit -m "feat: add user authentication"
# Commit with body
git commit -m "feat: add user authentication" -m "Implement JWT-based auth with refresh tokens"
# Amend last commit (change message or add files)
git add forgotten-file.ex
git commit --amend
# Amend without changing message
git commit --amend --no-edit
# Show unstaged changes
git diff
# Show staged changes
git diff --cached
git diff --staged
# Show changes in specific file
git diff path/to/file.ex
# Show changes between branches
git diff main..feature/new-feature
# Show changes between commits
git diff abc123..def456
# Show stats only
git diff --stat
# Start new feature
git checkout main
git pull origin main
git checkout -b feature/new-feature
# Work on feature
git add .
git commit -m "feat: implement new feature"
# Keep feature updated with main
git checkout main
git pull origin main
git checkout feature/new-feature
git merge main
# Push feature
git push -u origin feature/new-feature
# After PR is merged, clean up
git checkout main
git pull origin main
git branch -d feature/new-feature
# Keep feature branch up-to-date with clean history
git checkout feature/new-feature
git fetch origin
git rebase origin/main
# If conflicts occur, resolve them, then:
git add resolved-file.ex
git rebase --continue
# Abort rebase if needed
git rebase --abort
# Force push after rebase (careful!)
git push --force-with-lease origin feature/new-feature
# Default when possible - no merge commit
git checkout main
git merge feature/simple-feature
# Always create merge commit for history
git merge --no-ff feature/important-feature
# Combine all feature commits into one
git merge --squash feature/many-small-commits
git commit -m "feat: add complete feature"
# See conflicted files
git status
# See conflict markers in file
# <<<<<<< HEAD
# Current branch changes
# =======
# Incoming changes
# >>>>>>> feature/branch
# Edit files to resolve conflicts, then:
git add resolved-file.ex
git commit # Or git rebase --continue if rebasing
# Use merge tools
git mergetool
# Choose one side completely
git checkout --ours file.ex # Keep our version
git checkout --theirs file.ex # Keep their version
# Abort merge
git merge --abort
# Abort rebase
git rebase --abort
Clean up commit history before merging:
# Rebase last 3 commits
git rebase -i HEAD~3
# Rebase since main
git rebase -i main
# Interactive rebase options:
# pick - keep commit as-is
# reword - change commit message
# edit - modify commit
# squash - combine with previous commit
# fixup - like squash but discard message
# drop - remove commit
Example workflow:
# You have commits:
# abc123 fix typo
# def456 add feature
# ghi789 fix bug in feature
# jkl012 add tests
git rebase -i HEAD~4
# Change to:
# pick def456 add feature
# fixup ghi789 fix bug in feature
# squash jkl012 add tests
# reword abc123 fix typo
# View commit history
git log
# Compact one-line format
git log --oneline
# Graph view
git log --graph --oneline --all
# With file changes
git log --stat
# Search commits
git log --grep="authentication"
# Commits by author
git log --author="John"
# Commits in date range
git log --since="2 weeks ago"
git log --after="2024-01-01" --before="2024-02-01"
# Follow file history
git log --follow -- path/to/file.ex
# Show specific commit
git show abc123
# Undo uncommitted changes
git restore file.ex
git checkout -- file.ex # Old syntax
# Restore all files
git restore .
# Undo commit (keep changes)
git reset --soft HEAD~1
# Undo commit (discard changes) - DANGEROUS
git reset --hard HEAD~1
# Create new commit that undoes a commit
git revert abc123
# Revert merge commit
git revert -m 1 abc123
Temporarily save uncommitted changes:
# Stash changes
git stash
git stash push -m "work in progress on feature"
# Stash including untracked files
git stash -u
# List stashes
git stash list
# Apply most recent stash
git stash apply
# Apply and remove stash
git stash pop
# Apply specific stash
git stash apply stash@{2}
# Delete stash
git stash drop stash@{0}
# Clear all stashes
git stash clear
# Create branch from stash
git stash branch feature/from-stash
# View remotes
git remote -v
# Add remote
git remote add origin git@github.com:user/repo.git
# Change remote URL
git remote set-url origin git@github.com:user/new-repo.git
# Remove remote
git remote remove origin
# Rename remote
git remote rename origin upstream
# Fetch changes from remote
git fetch origin
# Fetch all remotes
git fetch --all
# Pull changes (fetch + merge)
git pull origin main
# Pull with rebase
git pull --rebase origin main
# Set upstream branch
git push -u origin feature/new-feature
git branch --set-upstream-to=origin/feature feature/new-feature
# Push to remote
git push origin main
# Push and set upstream
git push -u origin feature/new-feature
# Force push (CAREFUL!)
git push --force origin feature/branch
# Safer force push - fails if remote has new commits
git push --force-with-lease origin feature/branch
# Push all branches
git push --all origin
# Push tags
git push --tags
# Lightweight tag
git tag v1.0.0
# Annotated tag (preferred)
git tag -a v1.0.0 -m "Release version 1.0.0"
# Tag specific commit
git tag -a v1.0.0 abc123 -m "Release version 1.0.0"
# List tags
git tag
git tag -l "v1.*"
# View tag details
git show v1.0.0
# Push tag
git push origin v1.0.0
# Push all tags
git push origin --tags
# Delete local tag
git tag -d v1.0.0
# Delete remote tag
git push origin --delete v1.0.0
Apply specific commits to current branch:
# Apply single commit
git cherry-pick abc123
# Apply multiple commits
git cherry-pick abc123 def456
# Cherry-pick without committing
git cherry-pick -n abc123
Find which commit introduced a bug:
# Start bisect
git bisect start
git bisect bad # Current commit is bad
git bisect good abc123 # Known good commit
# Git will checkout commits to test
# After testing each:
git bisect good # or
git bisect bad
# When found, Git shows first bad commit
# Reset
git bisect reset
# Add submodule
git submodule add git@github.com:user/repo.git path/to/submodule
# Clone with submodules
git clone --recurse-submodules git@github.com:user/repo.git
# Update submodules
git submodule update --init --recursive
# Pull submodule updates
git submodule update --remote
# Using GitHub CLI (gh)
gh pr create --title "feat: add new feature" --body "Description of changes"
# Create draft PR
gh pr create --draft
# List PRs
gh pr list
# View PR
gh pr view 123
# Checkout PR locally
gh pr checkout 123
# Merge PR
gh pr merge 123 --squash
# Create issue
gh issue create --title "Bug: authentication fails" --body "Description"
# List issues
gh issue list
# View issue
gh issue view 123
# Close issue
gh issue close 123
Add to .gitconfig:
[alias]
co = checkout
br = branch
ci = commit
st = status
unstage = restore --staged
last = log -1 HEAD
lg = log --graph --oneline --all
cm = commit -m
ca = commit --amend
undo = reset --soft HEAD~1
sync = !git fetch origin && git rebase origin/main
clean-branches = !git branch --merged | grep -v \"\\*\" | xargs -n 1 git branch -d
.gitignore)--force-with-lease instead of --force# Move commit to new branch
git branch feature/new-branch
git reset --hard HEAD~1
git checkout feature/new-branch
git commit --amend
# Remove from history - CAREFUL!
git filter-branch --force --index-filter \
"git rm --cached --ignore-unmatch path/to/sensitive-file" \
--prune-empty --tag-name-filter cat -- --all
# Or use BFG Repo-Cleaner (faster)
bfg --delete-files sensitive-file
git reflog expire --expire=now --all
git gc --prune=now --aggressive
# Force push to update remote
git push --force --all
# Find commit where branch was
git reflog
# Recreate branch
git checkout -b recovered-branch abc123
# Undo merge (before pushing)
git reset --hard HEAD~1
# Undo merge (after pushing)
git revert -m 1 merge-commit-hash
This skill should be used when the user asks to "create a slash command", "add a command", "write a custom command", "define command arguments", "use command frontmatter", "organize commands", "create command with file references", "interactive command", "use AskUserQuestion in command", or needs guidance on slash command structure, YAML frontmatter fields, dynamic arguments, bash execution in commands, user interaction patterns, or command development best practices for Claude Code.
This skill should be used when the user asks to "create an agent", "add an agent", "write a subagent", "agent frontmatter", "when to use description", "agent examples", "agent tools", "agent colors", "autonomous agent", or needs guidance on agent structure, system prompts, triggering conditions, or agent development best practices for Claude Code plugins.
This skill should be used when the user asks to "create a hook", "add a PreToolUse/PostToolUse/Stop hook", "validate tool use", "implement prompt-based hooks", "use ${CLAUDE_PLUGIN_ROOT}", "set up event-driven automation", "block dangerous commands", or mentions hook events (PreToolUse, PostToolUse, Stop, SubagentStop, SessionStart, SessionEnd, UserPromptSubmit, PreCompact, Notification). Provides comprehensive guidance for creating and implementing Claude Code plugin hooks with focus on advanced prompt-based hooks API.