| name | git-operations |
| description | Common git operation patterns and commands. Use when working with git branches, commits, staging, rebasing, stashing, or any other git operations. Triggers include branching, committing, merging, rebasing, and syncing with remote repositories. |
Git Operations
Reusable patterns for common git operations in this repository.
Branch Operations
Create Feature Branch
git checkout main
git pull origin main
git checkout -b feature/<name>
Create Task Branch (Cascade)
git checkout <parent-branch>
git checkout -b task-N-<description>
Delete Branch
git branch -d <branch-name>
git branch -D <branch-name>
git push origin --delete <branch-name>
List Branches
git branch
git branch -r
git branch -a
Commit Operations
Standard Commit
git add <files>
git commit -m "<type>(<scope>): <description>"
Commit Types
feat - New feature
fix - Bug fix
docs - Documentation
style - Formatting
refactor - Code restructuring
test - Tests
chore - Maintenance
Amend Last Commit
git commit --amend -m "new message"
git add <files> && git commit --amend --no-edit
View Commit History
git log --oneline -10
git log --oneline --graph -20
git log --oneline -- <file>
Staging Operations
Stage Files
git add file1.py file2.py
git add "*.py"
git add .
Unstage Files
git restore --staged <file>
View Changes
git diff
git diff --staged
Sync Operations
Fetch Updates
git fetch origin
Pull Changes
git pull origin <branch>
Push Changes
git push origin <branch>
git push -u origin <branch>
git push --force-with-lease origin <branch>
Rebase Operations
Rebase on Branch
git checkout <feature-branch>
git rebase <base-branch>
Interactive Rebase
git rebase -i HEAD~<n>
Continue After Conflict
git add <resolved-files>
git rebase --continue
Abort Rebase
git rebase --abort
Stash Operations
Stash Changes
git stash
git stash push -m "description"
List Stashes
git stash list
Apply Stash
git stash pop
git stash apply
Drop Stash
git stash drop stash@{0}
Diff Operations
Compare Branches
git diff main..feature-branch
Compare Commits
git diff <commit1>..<commit2>
Show Changed Files
git diff --name-only main..HEAD
Reset Operations
Soft Reset (keep changes staged)
git reset --soft HEAD~1
Mixed Reset (keep changes unstaged)
git reset HEAD~1
Hard Reset (discard changes)
git reset --hard HEAD~1
Cherry Pick
Pick Single Commit
git cherry-pick <commit-sha>
Pick Without Commit
git cherry-pick --no-commit <commit-sha>
Tags
Create Tag
git tag v1.0.0
git tag -a v1.0.0 -m "Release 1.0.0"
Push Tags
git push origin v1.0.0
git push origin --tags
Safety Guidelines
- Never force push to main
- Use
--force-with-lease instead of --force
- Always pull before pushing
- Review diff before committing
- Don't commit sensitive data