Git Workflows

Common Git workflows: feature branches, releases, and collaboration

Feature Branch Workflow

Create Feature Branch

Start new feature development

git checkout -b feature/new-feature

Update Feature Branch

Keep feature branch up to date

git rebase origin/main

Push Feature Branch

Push feature branch to remote

git push -u origin feature/new-feature

Create Pull Request

Create PR on GitHub/GitLab

gh pr create --title "Add new feature"

Clean Up After Merge

Delete merged feature branch

git branch -d feature/new-feature

Git Flow Workflow

Initialize Git Flow

Set up Git Flow in repository

git flow init

Start Feature

Create feature branch

git flow feature start feature-name

Finish Feature

Complete and merge feature

git flow feature finish feature-name

Start Release

Create release branch

git flow release start 1.0.0

Finish Release

Complete release

git flow release finish 1.0.0

Start Hotfix

Create hotfix branch

git flow hotfix start hotfix-name

Finish Hotfix

Complete hotfix

git flow hotfix finish hotfix-name

Trunk-Based Development

Create Short-Lived Branch

Create branch for small changes

git checkout -b fix/typo

Commit Directly to Main

For small, safe changes

git commit -m "Fix typo"

Merge Back Quickly

Merge changes within hours

git merge fix/typo

Continuous Integration

Run tests before merge

git push && # CI runs automatically

Release Management

Create Release Branch

Branch for release preparation

git checkout -b release/v1.0.0

Version Bump

Update version numbers

npm version patch

Tag Release

Create release tag

git tag -a v1.0.0 -m "Release v1.0.0"

Push Tags

Push tags to remote

git push origin --tags

Merge to Main

Merge release to main

git checkout main && git merge release/v1.0.0

Collaboration Commands

Fetch Updates

Get latest changes

git fetch origin

Pull with Rebase

Update local branch

git pull --rebase origin main

Review Changes

See what changed

git log --oneline origin/main..HEAD

Push Force (Careful!)

Force push after rebase

git push --force-with-lease

Check Branch Status

See branch comparison

git status

Code Review Workflow

Request Review

Ask for code review

gh pr create --reviewer username

Address Comments

Fix review comments

git commit --amend

Update PR

Push changes to PR

git push origin feature-branch

Approve PR

Approve pull request

gh pr review --approve

Merge PR

Merge approved PR

gh pr merge --squash

Conflict Resolution

Check Conflicts

See conflict status

git status

Abort Merge

Cancel merge operation

git merge --abort

Resolve Conflicts

Edit conflicted files

git mergetool

Continue Merge

Complete merge after resolution

git commit

Skip Commit

Skip merge commit

git merge --no-commit

Common Patterns

Feature Branch Workflow

Complete 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-authentication

Git Flow Workflow

Structured 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 --tags

Release Workflow

Complete 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"

Collaboration Workflow

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-feature

Emergency Hotfix Workflow

Quick 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-bug

Code Review Checklist

GitHub 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
```

Tips & Best Practices

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