This message appears during a Git rebase operation, indicating Git is temporarily moving your branch pointer back to the common ancestor before replaying your commits on top of the target branch. It is an informational message, not an error.
When you run `git rebase`, Git displays the message "First, rewinding head to replay your work on top of it..." This is not an error but an informational message explaining what Git is doing internally. During a rebase, Git performs these steps: 1. Finds the common ancestor between your current branch and the target branch 2. Saves the changes (diffs) from each of your commits into temporary files 3. Resets your branch to the same commit as the target branch (the "rewinding" part) 4. Replays your commits one by one on top of the new base The "rewinding head" message indicates step 3 is happening - Git is moving the HEAD pointer back before applying your changes. This creates a linear history instead of a merge commit, making the commit history cleaner and easier to follow. This message is completely normal and expected during rebase operations. However, if the rebase encounters conflicts or stops unexpectedly, you may need to resolve issues before Git can complete the replay process.
The "rewinding head" message is Git's way of telling you what it's doing. If you see this message followed by successful completion, no action is needed:
$ git rebase main
First, rewinding head to replay your work on top of it...
Applying: Add new feature
Applying: Fix bug in feature
# Rebase completed successfullyYour commits have been replayed on top of the target branch.
If the rebase stops due to conflicts, Git will tell you which files need attention:
# Check the status to see conflicting files
git status
# Open and resolve conflicts in each file
# Look for conflict markers: <<<<<<<, =======, >>>>>>>
# After resolving, stage the files
git add <resolved-file>
# Continue the rebase
git rebase --continueRepeat this process for each commit that has conflicts.
Sometimes during rebase, a commit's changes become empty (already applied in the target branch). If Git complains about no changes:
# If git status shows no changes to commit
git rebase --skipThis skips the current commit and continues with the next one.
If you want to cancel the rebase and return to your original state:
# Abort rebase and restore original branch state
git rebase --abortThis returns your branch to exactly where it was before you started the rebase. No changes are lost.
After the rebase completes, verify your commits are in order:
# View the commit history
git log --oneline -10
# Compare with the remote (if applicable)
git log --oneline origin/main..HEAD
# Check branch status
git statusNote that your commit hashes will have changed since the commits were rewritten.
Why rebase changes commit hashes:
When Git "replays" your commits, it creates new commits with different hashes because the parent commit has changed. The content (diff) remains the same, but the commit metadata differs. This is why you should avoid rebasing commits that have already been pushed and shared with others.
Force pushing after rebase:
If you rebased a branch that was already pushed, you'll need to force push:
# Force push with lease (safer - fails if remote has new commits)
git push --force-with-lease
# Regular force push (use with caution)
git push --forceConfigure pull to always rebase:
To avoid merge commits when pulling:
# Set for current repository
git config pull.rebase true
# Set globally
git config --global pull.rebase trueDealing with stuck rebase state:
If Git gets into a bad state during rebase (rare), you can manually clean up:
# Check if rebase is in progress
ls .git/rebase-merge/ # or .git/rebase-apply/
# Use reflog to find your original commit
git reflog
# Hard reset to your original state
git reset --hard HEAD@{n} # where n is the reflog entryPreserving merge commits during rebase:
By default, rebase linearizes history and drops merge commits. To preserve them:
git rebase --rebase-merges mainwarning: 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