| name | git-workflow |
| description | Manage Git workflows including commits, branches, merges, and collaboration. Use when working with Git repositories, creating commits, managing branches, or resolving conflicts. |
| metadata | {"tags":"git, version-control, branching, commits, collaboration","platforms":"Claude, ChatGPT, Gemini"} |
Git Workflow
When to use this skill
- Creating meaningful commit messages
- Managing branches
- Merging code
- Resolving conflicts
- Collaborating with team
- Git best practices
Instructions
Step 1: Branch management
Create feature branch:
git checkout -b feature/feature-name
git checkout -b feature/feature-name <commit-hash>
Naming conventions:
feature/description: New features
bugfix/description: Bug fixes
hotfix/description: Urgent fixes
refactor/description: Code refactoring
docs/description: Documentation updates
Step 2: Making changes
Stage changes:
git add file1.py file2.js
git add .
git add -p
Check status:
git status
git diff
git diff --staged
Step 3: Committing
Write good commit messages:
git commit -m "type(scope): subject
Detailed description of what changed and why.
- Change 1
- Change 2
Fixes #123"
Commit types:
feat: New feature
fix: Bug fix
docs: Documentation
style: Formatting, no code change
refactor: Code refactoring
test: Adding tests
chore: Maintenance
Example:
git commit -m "feat(auth): add JWT authentication
- Implement JWT token generation
- Add token validation middleware
- Update user model with refresh token
Closes #42"
Step 4: Pushing changes
git push origin feature/feature-name
git push origin feature/feature-name --force-with-lease
git push -u origin feature/feature-name
Step 5: Pulling and updating
git pull origin main
git pull --rebase origin main
git fetch origin
Step 6: Merging
Merge feature branch:
git checkout main
git merge feature/feature-name
git merge --no-ff feature/feature-name
Rebase instead of merge:
git checkout feature/feature-name
git rebase main
git rebase --continue
git rebase --abort
Step 7: Resolving conflicts
When conflicts occur:
git status
<<<<<<< HEAD
Current branch code
=======
Incoming branch code
>>>>>>> feature-branch
# After resolving
git add <resolved-files>
git commit # For merge
git rebase --continue # For rebase
Step 8: Cleaning up
git branch -d feature/feature-name
git branch -D feature/feature-name
git push origin --delete feature/feature-name
git fetch --prune
Advanced workflows
Interactive rebase
git rebase -i HEAD~3
Stashing changes
git stash
git stash save "Work in progress on feature X"
git stash list
git stash apply
git stash pop
git stash apply stash@{2}
git stash drop stash@{0}
git stash clear
Cherry-picking
git cherry-pick <commit-hash>
git cherry-pick <hash1> <hash2> <hash3>
git cherry-pick -n <commit-hash>
Bisect (finding bugs)
git bisect start
git bisect bad
git bisect good <commit-hash>
git bisect good
git bisect bad
git bisect reset
Examples
Example 1: Feature development workflow
git checkout main
git pull origin main
git checkout -b feature/user-profile
git add src/profile/
git commit -m "feat(profile): add user profile page
- Create profile component
- Add profile API endpoints
- Add profile tests"
git fetch origin
git rebase origin/main
git push origin feature/user-profile
git checkout main
git pull origin main
git branch -d feature/user-profile
Example 2: Hotfix workflow
git checkout main
git pull origin main
git checkout -b hotfix/critical-bug
git add .
git commit -m "hotfix: fix critical login bug
Fixes authentication bypass vulnerability
Fixes #999"
git push origin hotfix/critical-bug
git checkout main
git pull origin main
git branch -d hotfix/critical-bug
Example 3: Collaborative workflow
git checkout main
git pull origin main
git checkout -b feature/new-feature
git fetch origin
git rebase origin/main
git push origin feature/new-feature
git pull origin feature/new-feature --rebase
git add .
git rebase --continue
git push origin feature/new-feature --force-with-lease
Best practices
- Commit often: Small, focused commits
- Meaningful messages: Explain what and why
- Pull before push: Stay updated
- Review before commit: Check what you're committing
- Use branches: Never commit directly to main
- Keep history clean: Rebase feature branches
- Test before push: Run tests locally
- Write descriptive branch names: Easy to understand
- Delete merged branches: Keep repository clean
- Use .gitignore: Don't commit generated files
Common patterns
Undo last commit (keep changes)
git reset --soft HEAD~1
Undo last commit (discard changes)
git reset --hard HEAD~1
Amend last commit
git commit --amend -m "New message"
git add forgotten-file.txt
git commit --amend --no-edit
View history
git log
git log --oneline
git log --oneline --graph --all
git log -5
git log --author="John"
git log --since="2 weeks ago"
Find commits
git log --grep="keyword"
git log -S "function_name"
git log --follow -- path/to/file
Troubleshooting
Accidentally committed to wrong branch
git branch feature/correct-branch
git reset --hard HEAD~1
git checkout feature/correct-branch
Need to undo a merge
git reset --hard HEAD~1
git revert -m 1 <merge-commit-hash>
Recover deleted branch
git reflog
git checkout -b recovered-branch <commit-hash>
Sync fork with upstream
git remote add upstream https://github.com/original/repo.git
git fetch upstream
git checkout main
git merge upstream/main
git push origin main
Git configuration
User setup
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"
Aliases
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.ci commit
git config --global alias.st status
git config --global alias.unstage 'reset HEAD --'
git config --global alias.last 'log -1 HEAD'
git config --global alias.lg 'log --oneline --graph --all'
Editor
git config --global core.editor "code --wait"
git config --global core.editor "vim"
References