# Preserve a commit made on the wrong Git branch

Canonical: https://githtml.com/guides/git-committed-to-wrong-branch-preserve
Published: 2026-11-23
Publisher: WaveTech LLC / gitHtml

First create a branch pointing to the misplaced commit so the work has a clear home. Then determine whether the original branch’s commit was pushed or used by others. Moving unpublished history and reversing a shared commit require different procedures. Preserve the work before attempting either, and avoid using a hard reset as an automatic cleanup step.

## Save the commit before deciding how to remove it

A wrong-branch commit is still a valid repository object. The immediate priority is preserving its identifier and giving it an appropriate branch reference. Inspect the last few commits to confirm whether one commit or several were misplaced, and whether the latest commit is a merge. Do not assume HEAD~1 is the desired original branch position in every case.

Next establish publication status. A local branch being ahead of a stale tracking ref does not prove the commit was never shared; fetch and check the collaboration context. Someone may have received it through another branch or a patch. When uncertain, treat the history as shared until you have evidence otherwise.

## Create a named preservation point

The example creates a branch at the current tip without switching or altering files. Use a new name and verify the tip first. This preserves the commit graph but leaves any uncommitted modifications separate. The remaining repair depends on where the work should ultimately land.

1. For an unpublished latest commit with a verified parent, a carefully planned soft or mixed reset can move the original branch while keeping content; inspect resulting edits before switching.
2. For shared history, consider a reviewed revert on the original branch and a separate integration of the intended fix where it belongs, coordinating with maintainers.

````shell
git status --short --branch
git log --oneline -5
git branch feature/misplaced-fix HEAD
git show --no-patch --oneline feature/misplaced-fix
git branch -vv
````

## Avoid treating branch cleanup as the first goal

You may be able to continue directly on the new branch if it has the right base. If the intended destination differs, inspect dependencies before cherry-picking the saved commit. Keep the preservation branch until the final placement and any reversal are verified.

A revert on the original branch does not automatically remove the fix from every other branch, and moving a local branch does not update its remote counterpart. Record each intended outcome separately: where the work should remain, where it should be absent, and whether collaborators need a follow-up. This prevents a simple placement mistake from turning into an uncoordinated rewrite of shared history.

1. If two consecutive commits belong to the feature, preserve the newest tip and inspect both patches before deciding the original branch’s target. Rewinding by one commit would leave half the feature behind. Identify the last intended original-branch commit by its content and ancestry rather than counting blindly.
2. When the misplaced commit depends on an earlier change already present only on the wrong branch, transferring that commit alone may not work. Read the dependency’s patch and decide whether to transfer it, adapt the feature, or choose another base. Verify the destination’s behavior before retiring the preservation branch.

## Sources and further reading

- [Git reference: git-branch](https://git-scm.com/docs/git-branch)
- [Git reference: git-reset](https://git-scm.com/docs/git-reset)
- [Git reference: git-revert](https://git-scm.com/docs/git-revert)

## Related guides

- [Fix “current branch has no upstream” deliberately](https://githtml.com/guides/git-current-branch-no-upstream-error)
- [Save commits made in detached HEAD state](https://githtml.com/guides/git-detached-head-save-commits)
- [Investigate Git’s dubious-ownership warning safely](https://githtml.com/guides/git-dubious-ownership-safe-directory)
- [Diagnose a Git diff that marks every line changed](https://githtml.com/guides/git-entire-file-changed-line-endings)

Editorial approach: https://githtml.com/guides/about
