Common Git workflows: feature branches, releases, and collaboration
Start new feature development
git checkout -b feature/new-featureKeep feature branch up to date
git rebase origin/mainPush feature branch to remote
git push -u origin feature/new-featureCreate PR on GitHub/GitLab
gh pr create --title "Add new feature"Delete merged feature branch
git branch -d feature/new-featureSet up Git Flow in repository
git flow initCreate feature branch
git flow feature start feature-nameComplete and merge feature
git flow feature finish feature-nameCreate release branch
git flow release start 1.0.0Complete release
git flow release finish 1.0.0Create hotfix branch
git flow hotfix start hotfix-nameComplete hotfix
git flow hotfix finish hotfix-nameCreate branch for small changes
git checkout -b fix/typoFor small, safe changes
git commit -m "Fix typo"Merge changes within hours
git merge fix/typoRun tests before merge
git push && # CI runs automaticallyBranch for release preparation
git checkout -b release/v1.0.0Update version numbers
npm version patchCreate release tag
git tag -a v1.0.0 -m "Release v1.0.0"Push tags to remote
git push origin --tagsMerge release to main
git checkout main && git merge release/v1.0.0Get latest changes
git fetch originUpdate local branch
git pull --rebase origin mainSee what changed
git log --oneline origin/main..HEADForce push after rebase
git push --force-with-leaseSee branch comparison
git statusAsk for code review
gh pr create --reviewer usernameFix review comments
git commit --amendPush changes to PR
git push origin feature-branchApprove pull request
gh pr review --approveMerge approved PR
gh pr merge --squashSee conflict status
git statusCancel merge operation
git merge --abortEdit conflicted files
git mergetoolComplete merge after resolution
git commitSkip merge commit
git merge --no-commitComplete feature development workflow
# 1. Start new feature
git checkout main
git pull origin main
git checkout -b feature/user-authentication
# 2. Work on feature
git add .
git commit -m "Add user authentication system"
git push origin feature/user-authentication
# 3. Keep feature up to date
git fetch origin
git rebase origin/main
# 4. Create pull request
gh pr create --title "Add user authentication" --body "Implements user login/logout functionality"
# 5. After review and approval
gh pr merge --squash
# 6. Clean up
git checkout main
git pull origin main
git branch -d feature/user-authentication
git push origin --delete feature/user-authenticationStructured workflow for releases
# Initialize Git Flow
git flow init
# Feature development
git flow feature start login-system
# ... work on feature ...
git flow feature finish login-system
# Release preparation
git flow release start 1.2.0
# ... prepare release ...
git flow release finish 1.2.0
# Hotfix for production
git flow hotfix start security-patch
# ... fix issue ...
git flow hotfix finish security-patch
# Push all branches and tags
git push origin --all
git push origin --tagsComplete release process
# 1. Create release branch
git checkout main
git pull origin main
git checkout -b release/v2.1.0
# 2. Update version and changelog
npm version minor
# Edit CHANGELOG.md
# 3. Commit release changes
git add .
git commit -m "Prepare release v2.1.0"
# 4. Create release tag
git tag -a v2.1.0 -m "Release v2.1.0"
# 5. Merge to main and develop
git checkout main
git merge release/v2.1.0
git push origin main
git checkout develop
git merge release/v2.1.0
git push origin develop
# 6. Push tags
git push origin --tags
# 7. Clean up
git branch -d release/v2.1.0
# 8. Create GitHub release
gh release create v2.1.0 --title "Release v2.1.0" --notes "New features and bug fixes"Team collaboration patterns
# 1. Start of day - sync with team
git checkout main
git pull origin main
# 2. Create feature branch
git checkout -b feature/team-feature
# 3. Work and commit frequently
git add .
git commit -m "Add feature component"
git push origin feature/team-feature
# 4. Keep branch updated
git fetch origin
git rebase origin/main
# 5. Resolve conflicts if any
git status
# Edit conflicted files
git add .
git rebase --continue
# 6. Force push after rebase (safely)
git push --force-with-lease origin feature/team-feature
# 7. Create PR and request review
gh pr create --title "Add team feature" --reviewer @team
# 8. Address review feedback
git commit --amend
git push --force-with-lease origin feature/team-featureQuick fix for production issues
# 1. Create hotfix branch from main
git checkout main
git pull origin main
git checkout -b hotfix/critical-bug
# 2. Fix the issue
# ... make minimal changes ...
git add .
git commit -m "Fix critical security vulnerability"
# 3. Test the fix
npm test
npm run build
# 4. Merge to main and tag
git checkout main
git merge hotfix/critical-bug
git tag -a v1.0.1 -m "Hotfix v1.0.1"
# 5. Deploy immediately
git push origin main
git push origin --tags
# 6. Create hotfix release
gh release create v1.0.1 --title "Critical Security Fix" --notes "Immediate deployment required"
# 7. Merge to develop
git checkout develop
git merge hotfix/critical-bug
git push origin develop
# 8. Clean up
git branch -d hotfix/critical-bugGitHub PR review workflow
# PR Review Process
## Before creating PR:
- [ ] Code follows style guidelines
- [ ] All tests pass
- [ ] No console.log statements
- [ ] Documentation updated
- [ ] Branch is up to date with main
## PR Description template:
```
## Changes
- Brief description of changes
## Testing
- [ ] Unit tests added/updated
- [ ] Manual testing completed
- [ ] Cross-browser testing done
## Screenshots (if UI changes)
- Before/after screenshots
## Checklist
- [ ] Self-review completed
- [ ] Code follows project standards
- [ ] Documentation updated
```
## Review commands:
```
# Request review
gh pr create --reviewer username1,username2
# Check review status
gh pr view --json reviewDecision
# Merge after approval
gh pr merge --squash
```Keep feature branches short-lived (hours to days, not weeks)
Use descriptive branch names: feature/user-auth, fix/login-bug
Write clear commit messages: feat: add user authentication
Always pull latest changes before starting new work
Use --force-with-lease instead of --force for safety