Overview
Rebasing is a Git operation that moves or combines commits from one branch onto another. It’s an alternative to merging that creates a linear project history. GitHub Desktop provides a safe and intuitive interface for rebasing.Linear History
Create a clean, linear commit history
Conflict Detection
Preview conflicts before starting the rebase
Interactive Progress
See real-time progress as commits are applied
Force Push Support
Safely force push with —force-with-lease
Understanding Rebase
What is Rebasing?
Rebasing rewrites commit history by:- Taking commits from your current branch
- Temporarily removing them
- Updating the base branch to the target
- Reapplying your commits on top of the new base
Rebase vs. Merge
- Rebase
- Merge
Linear History:Characteristics:
- Creates linear history
- Rewrites commits (new SHAs)
- Cleaner history
- Requires force push if already pushed
When to Use Rebase
Good Use Cases
Update Feature Branch
Keep your feature branch up to date with main before merging
Clean Up History
Create a clean, linear history before creating a pull request
Local Commits
Reorganize commits that haven’t been pushed yet
Interactive Cleanup
Squash, edit, or reorder commits before pushing
When to Avoid Rebase
Avoid rebasing when:- Commits are on a shared branch
- Other developers have based work on your commits
- Working on the repository’s main/default branch
- You’re unsure about the impact
- Multiple people are working on the same feature branch
Rebasing in GitHub Desktop
Basic Rebase Workflow
1
Switch to Branch
Check out the branch you want to rebase (e.g., your feature branch)
2
Open Rebase Dialog
Click Branch > Rebase current branch
3
Select Base Branch
Choose the branch to rebase onto (usually
main or develop)4
Review Information
GitHub Desktop shows:
- Number of commits to rebase
- Potential conflict warnings
- Remote commit warnings (if applicable)
5
Start Rebase
Click Begin rebase
6
Monitor Progress
Watch as commits are applied one by one
7
Handle Conflicts (if any)
Resolve any conflicts that arise during the rebase
Rebase Implementation
From the technical documentation and source code:Testing the Rebase
Before starting, GitHub Desktop determines:Progress Tracking
Rebase State Detection
GitHub Desktop detects ongoing rebases:Handling Conflicts During Rebase
When Conflicts Occur
If a commit can’t be applied cleanly:1
Rebase Pauses
GitHub Desktop stops at the conflicted commit
2
Shows Conflict Info
Displays:
- Which commit caused the conflict
- Conflicted files
- Progress (e.g., “Commit 3 of 7”)
3
Resolve Conflicts
Fix conflicts in each file:
- Open in editor
- Choose “ours” or “theirs”
- Manually edit conflict markers
4
Continue or Skip
After resolving:
- Continue: Apply this commit and continue
- Skip: Omit this commit (if it’s empty after conflicts)
- Abort: Cancel the entire rebase
Continue Rebase
After resolving conflicts:If a commit becomes empty after conflict resolution (all changes were already in the base), GitHub Desktop automatically runs
git rebase --skip.Abort Rebase
To cancel the rebase:1
Click Abort
Click Abort rebase in the rebase progress banner
2
Confirm
If you’ve resolved conflicts, confirm you want to discard that work
3
Return to Original State
Branch returns to its state before the rebase started
Force Pushing After Rebase
Why Force Push?
After rebasing commits that were already pushed:- Commit SHAs have changed
- Remote branch has the old commits
- You must force push to update the remote
Safe Force Push
GitHub Desktop uses--force-with-lease for safety:
1
Complete Rebase
Finish the rebase successfully
2
Force Push Indicator
GitHub Desktop shows Force push origin button
3
Review Warning
If confirmation is enabled, review the force push warning
4
Force Push
Click Force push origin
--force-with-lease?
- Fails if remote was updated by someone else
- Prevents overwriting others’ commits
- Safer than
--force
Force Push State Tracking
GitHub Desktop tracks branches eligible for force push:Rebase Confirmation Dialog
If enabled in preferences, GitHub Desktop shows a warning when:Remote Commits Detected
When rebasing a branch with pushed commits: Warning shows:- Number of commits that will be rewritten
- Explanation of force push requirement
- Impact on collaborators
- Option to continue or cancel
Rebase vs. Merge: Choosing the Right Tool
Use Rebase When:
-
Cleaning Up Local Commits
- Before creating a pull request
- Commits haven’t been pushed
- Want a clean, linear history
-
Updating Feature Branches
- Bringing latest changes from main
- Before merging via PR
- No one else is on the branch
-
Maintaining Clean History
- Project prefers linear history
- Team understands rebase workflow
- Following agreed conventions
Use Merge When:
-
Shared Branches
- Multiple people working on the branch
- Commits are public
- Want to preserve exact history
-
Main/Default Branch
- Never rebase the main branch
- Merge feature branches into it
- Keep stable history
-
Unsure About Impact
- When in doubt, merge is safer
- Can always rebase later locally
- Easier to undo
Best Practices
-
Rebase Often
- Keep feature branches updated with main
- Rebase frequently to avoid large conflicts
- Makes final merge easier
-
Test After Rebasing
- Run tests after completing a rebase
- Conflicts can introduce bugs
- Verify everything still works
-
One Commit at a Time
- Resolve conflicts commit-by-commit
- Don’t rush through conflicts
- Test between conflict resolutions if possible
-
Use Descriptive Commit Messages
- Makes rebasing easier to follow
- Helps identify which commits to keep/skip
- Useful when resolving conflicts
-
Enable Force Push Confirmation
- Requires explicit confirmation before force pushing
- Prevents accidental overwrites
- Enabled by default in Preferences > Git
-
Understand the Consequences
- Know that rebase rewrites history
- Be prepared to force push
- Communicate with team
Common Rebase Scenarios
Update Feature Branch from Main
Clean Up Before Pull Request
Rebase After Main Updated
Troubleshooting
Too Many Conflicts
Too Many Conflicts
If you encounter overwhelming conflicts:
- Abort the rebase: Better to merge than fight conflicts
- Update more frequently: Smaller, frequent rebases have fewer conflicts
- Consider merge instead: Merging might be more appropriate
- Ask for help: Consult the commit authors
Lost Commits After Abort
Lost Commits After Abort
If commits seem lost after aborting:
- They’re not actually lost
- Check
git reflogto find them - Branch pointer was just moved back
- Can recover with
git reset --hard <sha>
Force Push Rejected
Force Push Rejected
If force push fails:
- Branch is protected: Check branch protection rules
- No force push permission: You may not have rights
- Someone pushed: Another commit was pushed (fetch first)
- Wrong branch: Verify you’re on the correct branch
Rebase Stuck or Frozen
Rebase Stuck or Frozen
If rebase appears stuck:
- Check for hook scripts that are running
- Look for prompts in terminal
- Verify disk space available
- Try aborting and restarting