How to merge pull requests in GitHub

Merging pull requests integrates reviewed and approved code changes into the main codebase while maintaining project history and quality standards. As the creator of CoreUI, a widely used open-source UI library, I’ve merged thousands of pull requests in open-source projects throughout my 25 years of development experience. The most appropriate approach depends on project requirements: merge commits preserve full history, squash creates clean linear history, and rebase maintains individual commits. This method enables flexible merge strategies, automatic issue closing, and maintains clear project evolution through controlled integration.

Review pull request, ensure all checks pass, choose merge strategy (merge commit, squash, or rebase), then click merge button.

Merge strategies in GitHub interface:

  1. Create a merge commit (default):

    • Preserves all commits from feature branch
    • Creates merge commit in main branch
    • Shows complete development history
    • Best for: Feature branches with meaningful commits
  2. Squash and merge:

    • Combines all commits into single commit
    • Creates clean linear history
    • Best for: Feature branches with many small commits
  3. Rebase and merge:

    • Replays commits onto base branch
    • No merge commit created
    • Linear history maintained
    • Best for: Clean commit history without merge commits

Using GitHub interface:

  1. Navigate to pull request
  2. Review changes and approvals
  3. Ensure all status checks pass (CI/CD, tests)
  4. Click “Merge pull request” dropdown
  5. Select merge strategy
  6. Edit commit message if needed
  7. Click “Confirm merge”
  8. Optionally delete feature branch

Using GitHub CLI:

# Merge with default strategy (merge commit)
gh pr merge 123

# Squash and merge
gh pr merge 123 --squash

# Rebase and merge
gh pr merge 123 --rebase

# Merge with custom commit message
gh pr merge 123 --squash --body "Implemented user authentication with JWT"

# Auto-merge when checks pass
gh pr merge 123 --auto --squash

# Merge and delete branch
gh pr merge 123 --delete-branch

# View PR status before merging
gh pr view 123
gh pr checks 123

Using Git commands (after PR approval):

# Fetch latest changes
git fetch origin

# Checkout main branch
git checkout main

# Pull latest main
git pull origin main

# Merge PR branch (creates merge commit)
git merge origin/feature-branch

# Push to main
git push origin main

# Or squash merge locally
git merge --squash origin/feature-branch
git commit -m "Add authentication feature"
git push origin main

Here the GitHub interface provides three merge strategies with visual confirmation. All commits from the feature branch are preserved with merge commit strategy, showing complete development context. Squash merge creates a single, clean commit combining all feature branch changes, ideal for atomic feature integration. Rebase merge applies commits individually onto main branch without merge commit, maintaining linear history. GitHub CLI streamlines merging from terminal with same strategy options. The –auto flag enables automatic merging when all required checks pass. Deleting the feature branch after merge keeps repository clean.

Best Practice Note:

This is the pull request merge workflow we use in CoreUI open-source development to maintain clean history while preserving important development context. Require status checks and approvals before allowing merge to enforce quality standards, use squash merge for feature branches to keep main branch history focused on features rather than development iterations, and include “Closes #123” in merge commit messages to automatically close related issues when PR merges.


Speed up your responsive apps and websites with fully-featured, ready-to-use open-source admin panel templates—free to use and built for efficiency.


About the Author