This warning appears on GitHub pull requests when your feature branch is behind the base branch (usually main or master). You need to update your branch with the latest changes from the base branch before merging, either by merging or rebasing.
The message "This branch is out-of-date with the base branch" appears in GitHub's pull request interface when your feature branch doesn't include all the commits that have been added to the base branch since you created or last updated your branch. This happens because Git repositories evolve continuously. While you were working on your feature branch, other developers merged their changes into the base branch (typically `main` or `master`). Your branch has now "diverged" from the base branchβit's missing commits that exist there. GitHub displays this warning because: 1. **Merge conflicts might exist**: The new commits in the base branch might conflict with your changes 2. **Tests might fail**: Your code might work alone but break when combined with new changes 3. **Branch protection rules**: Many repositories require branches to be up-to-date before merging 4. **Code review accuracy**: Reviewers should see how your changes interact with the current codebase
The simplest way to update your branch is directly through GitHub's web interface:
1. Navigate to your pull request on GitHub
2. Look for the yellow warning banner that says "This branch is out-of-date with the base branch"
3. Click the "Update branch" button
Two options appear:
- "Update with merge commit" - Creates a merge commit (default)
- "Update with rebase" - Rebases your commits (if enabled by repo settings)Note: The "Update with rebase" option must be enabled in repository settings under Settings > General > Pull Requests > "Allow rebase merging".
This method automatically fetches the latest changes and updates your branch without needing to use the command line.
If you prefer working locally or need more control, merge the base branch into your feature branch:
# Ensure you're on your feature branch
git checkout your-feature-branch
# Fetch the latest changes from remote
git fetch origin
# Merge the base branch into your branch
git merge origin/main
# If there are conflicts, resolve them, then:
git add .
git commit -m "Merge main into feature branch"
# Push the updated branch
git push origin your-feature-branchThis creates a merge commit that brings your branch up to date. Your branch history will show the point where you merged in the base branch changes.
Rebasing creates a cleaner history by replaying your commits on top of the base branch:
# Ensure you're on your feature branch
git checkout your-feature-branch
# Fetch the latest changes
git fetch origin
# Rebase your branch onto the base branch
git rebase origin/main
# If conflicts occur, resolve them for each commit:
# 1. Edit conflicting files
# 2. git add <resolved-files>
# 3. git rebase --continue
# Force push since history was rewritten
git push --force-with-lease origin your-feature-branchImportant: Rebasing rewrites commit history. Use --force-with-lease instead of --force to prevent accidentally overwriting others' work if they've pushed to your branch.
Warning: Don't rebase branches that others are working on or that have been reviewed, as it changes commit hashes.
If updating causes conflicts, you'll need to resolve them:
# After git merge or during git rebase, if conflicts occur:
# See which files have conflicts
git status
# Open conflicting files - look for conflict markers:
<<<<<<< HEAD
Your changes
=======
Changes from base branch
>>>>>>> origin/main
# Edit the files to resolve conflicts (remove markers, keep correct code)
# After resolving all conflicts:
git add <resolved-files>
# For merge:
git commit -m "Resolve merge conflicts with main"
# For rebase:
git rebase --continue
# Push your changes
git push origin your-feature-branch
# (use --force-with-lease if rebasing)Tip: Use a merge tool for complex conflicts:
git mergetoolRepository administrators can enable automatic branch updates:
1. Go to repository Settings
2. Navigate to General > Pull Requests
3. Enable "Always suggest updating pull request branches"
4. Optionally enable "Automatically update head branches" for merge queue
For merge queues (GitHub Enterprise or public repos):
# In branch protection rules, you can require:
- "Require branches to be up to date before merging"
- Configure merge queue settingsThis ensures PRs are automatically kept in sync or clearly marked when they need updates.
The GitHub CLI provides a convenient way to sync your branch:
# Install GitHub CLI if needed (https://cli.github.com/)
# Sync your branch with the base branch
gh pr checkout <pr-number>
gh repo sync
# Or use standard git commands through gh:
gh pr checkout <pr-number>
git fetch origin
git merge origin/main
git push
# You can also update via the API:
gh api \
--method PUT \
/repos/{owner}/{repo}/pulls/{pull_number}/update-branch \
-f update_method='merge'The CLI makes it easy to switch between PRs and keep them updated.
### Merge vs Rebase: Choosing the Right Strategy
Use Merge when:
- Working in a shared branch with multiple contributors
- You want to preserve the exact history of when changes were integrated
- Your team's workflow prefers merge commits
- The PR has already been reviewed (rebase changes commit hashes)
Use Rebase when:
- You want a linear, clean commit history
- You're the only one working on the branch
- The branch hasn't been reviewed yet
- Your team prefers squash-and-merge or rebase workflows
### Branch Protection Rules
Many organizations configure branch protection rules that require branches to be up-to-date:
# Common protection settings:
- Require status checks to pass before merging
- Require branches to be up to date before merging
- Require linear history (forces rebase or squash)
- Require merge queueWhen "Require branches to be up to date" is enabled:
1. The merge button is disabled if your branch is behind
2. You must update before CI checks will run
3. This prevents "semantic conflicts" where tests pass individually but fail together
### Handling Large Divergence
If your branch is significantly behind (many commits), consider:
# Check how far behind you are
git fetch origin
git rev-list --count HEAD..origin/main
# Shows number of commits you're behind
# If it's substantial, consider:
# 1. Creating a new branch from main
# 2. Cherry-picking your commits
git checkout -b new-feature-branch origin/main
git cherry-pick <commit1> <commit2> ...
# Or use interactive rebase to clean up first
git rebase -i origin/main### Merge Queue Behavior
GitHub's merge queue works by:
1. Taking PRs that are ready to merge
2. Creating a temporary branch with all queued PRs merged together
3. Running CI on this combined state
4. Merging successful builds, rejecting failures
If your PR is out of date when entering the queue:
- It will be automatically rebased/merged with the current base
- If conflicts occur, your PR is removed from the queue
- You'll need to manually update and re-enter the queue
### Git Configuration for Easier Updates
# Set up convenient aliases
git config --global alias.update '!git fetch origin && git merge origin/main'
git config --global alias.sync '!git fetch origin && git rebase origin/main'
# Configure default behavior for pull
git config --global pull.rebase true # Prefer rebase on pull
# Or
git config --global pull.rebase false # Prefer merge on pull
# Set up autostash for rebasing
git config --global rebase.autoStash true### Preventing Out-of-Date Branches
Best practices to minimize this issue:
1. Keep PRs small: Smaller PRs merge faster, less chance of falling behind
2. Merge frequently: Don't let PRs sit for weeks
3. Rebase regularly: If working on a long-running branch, rebase daily
4. Use draft PRs: Create drafts early to catch conflicts sooner
5. Enable branch update notifications: GitHub can notify when your PR needs updating
### CI/CD Considerations
When your branch is out of date:
- Some CI systems won't run until you update
- Tests might pass on your branch but fail when merged
- Consider running tests against a merge of your branch + main:
# GitHub Actions example
on:
pull_request:
types: [opened, synchronize]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
# Checkout the merge commit for accurate testing
ref: refs/pull/${{ github.event.pull_request.number }}/mergewarning: BOM detected in file, this may cause issues
UTF-8 Byte Order Mark (BOM) detected in file
fatal: Server does not support --shallow-exclude
Server does not support --shallow-exclude
warning: filtering out blobs larger than limit
Git partial clone filtering large blobs warning
fatal: Server does not support --shallow-since
Server does not support --shallow-since in Git
kex_exchange_identification: Connection closed by remote host
Connection closed by remote host when connecting to Git server