| name | git-workflow |
| description | Quick reference for common Git commands and workflows. Use when working with version control, committing changes, managing branches, or resolving Git issues. Covers daily Git operations, branching strategies, and troubleshooting. |
Git Workflow
Overview
A concise reference for common Git commands and workflows used in daily development. This skill provides quick access to frequently-used Git operations without searching documentation.
Daily Workflow
Check Status and Changes
git status
git diff
git diff --cached
git log --oneline --graph --all
Staging and Committing
git add <file1> <file2>
git add .
git add -u
git commit -m "Commit message"
git commit -am "Commit message"
git commit --amend
Syncing with Remote
git fetch origin
git pull origin main
git push origin main
git push -u origin <branch-name>
Branching
Creating and Switching Branches
git branch <branch-name>
git checkout <branch-name>
git checkout -b <branch-name>
git checkout -
git branch -a
Merging and Rebasing
git merge <branch-name>
git rebase main
git rebase -i HEAD~3
git merge --abort
git rebase --abort
Deleting Branches
git branch -d <branch-name>
git branch -D <branch-name>
git push origin --delete <branch-name>
Undoing Changes
Unstage and Discard
git restore --staged <file>
git restore <file>
git restore .
Reverting Commits
git revert <commit-hash>
git reset --soft HEAD~1
git reset --hard HEAD~1
git reset --hard <commit-hash>
Stashing
git stash
git stash save "Work in progress"
git stash list
git stash apply
git stash pop
git stash apply stash@{2}
git stash drop stash@{0}
git stash clear
Repository Setup
Initializing and Cloning
git init
git clone <url>
git clone <url> <directory>
git clone -b <branch-name> <url>
Remote Management
git remote add origin <url>
git remote -v
git remote set-url origin <new-url>
git remote remove origin
Troubleshooting
Conflict Resolution
git status
git add <resolved-file>
git commit
git merge --abort
Finding and Inspecting
git log -S "search term"
git show <commit-hash>
git show <commit-hash>:<file-path>
git blame <file>
git reflog
Cleaning Up
git clean -n
git clean -f
git clean -fd
Best Practices
Commit Messages
git commit -m "feat: Add user authentication"
git commit -m "fix: Resolve login redirect bug"
git commit -m "docs: Update API documentation"
git commit -m "refactor: Simplify validation logic"
Branch Naming
feature/<feature-name> # New features
bugfix/<bug-name> # Bug fixes
hotfix/<issue> # Urgent fixes
release/<version> # Release preparation
Common Workflows
Feature Branch Workflow:
git checkout -b feature/new-feature
git add .
git commit -m "feat: Implement new feature"
git push -u origin feature/new-feature
git checkout main
git pull origin main
git merge feature/new-feature
git push origin main
git branch -d feature/new-feature
git push origin --delete feature/new-feature
Quick Tips
- Undo last commit but keep changes:
git reset --soft HEAD~1
- View graphical log:
git log --oneline --graph --all --decorate
- Cherry-pick specific commit:
git cherry-pick <commit-hash>
- Create tag:
git tag -a v1.0.0 -m "Version 1.0.0"
- View diff between branches:
git diff branch1..branch2
- Update last commit message:
git commit --amend -m "New message"
- List files in commit:
git show --name-only <commit-hash>