Git Branching & Merging Cheatsheet

Complete guide to Git branching strategies, merge vs rebase, conflict resolution, and branch management.

Branch Management

# Create and switch to new branch
git checkout -b feature/my-feature

# Create branch from specific commit
git branch bugfix/fix-login abc1234

# List all branches (local + remote)
git branch -a

# Delete merged branch
git branch -d feature/done

# Force delete unmerged branch
git branch -D feature/abandoned

# Rename current branch
git branch -m new-name

Merge vs Rebase

FeatureMergeRebase
HistoryPreserves full historyLinear history
Merge commitCreates merge commitNo extra commits
Best forShared branchesLocal/feature branches
SafetyNever rewrites historyRewrites history (dangerous on shared)

Resolving Merge Conflicts

# After a merge conflict:
# 1. Open conflicting files — look for markers:
<<<<<<< HEAD
your changes
=======
their changes
>>>>>>> feature/branch

# 2. Edit to resolve, then:
git add resolved-file.js
git commit

Common Branching Strategies

Git Flow

main → production, develop → integration, feature/* → new features, release/* → release prep, hotfix/* → urgent fixes

Trunk-Based Development

Everyone commits to main with short-lived feature branches. Requires good CI/CD.

GitHub Flow

main is always deployable. Create branch → commit → PR → review → merge → deploy.

Need These Tools as an API?

TextForge API offers 20+ developer toolkit endpoints. Free tier: 50 requests/day.

Try TextForge API Free →

Related Tools