How can I push a specific commit to a remote, and not previous commits?
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
Git does not normally push a single isolated commit as if it were detached from its parent history. What you actually push is a branch tip, so the safe way to deliver one specific change without earlier local commits is to start from a clean base and copy only the desired commit onto that base.
Why git push <sha> Is Not the Right Mental Model
Each commit depends on its parent chain. If the remote branch does not already contain that parent history, the commit cannot simply be “pushed by itself” onto the branch in a clean, reviewable way.
That is why the usual solution is not a special push syntax. It is a history-construction step:
- start from the target base branch
- copy the wanted commit
- push the new branch
Use cherry-pick on a Clean Branch
The most common and safest workflow is to create a new branch from the remote base branch and cherry-pick the desired commit onto it.
Now the remote branch contains only the selected change on top of origin/main, which is exactly what most people mean when they ask to push one specific commit.
Check That You Really Copied Only That Change
Before pushing, inspect the branch relative to the base. This prevents accidental leakage of unfinished local work.
If the cherry-pick was clean, you should see only the intended commit and any conflict-resolution edits required to apply it on the target base.
Handle Dependencies Explicitly
Some commits are not truly standalone. A fix may depend on earlier refactors, renames, or schema changes. In that case, cherry-picking only one commit can produce a branch that compiles or tests badly.
If that happens:
- identify the minimum prerequisite commits
- cherry-pick those in dependency order
- run tests after each step
When the dependency chain becomes large, a focused merge or backport branch may be clearer than selective picking.
Use Patch Export for Extra Control
If you want a more explicit transfer step, you can export one commit as a patch and apply it on a clean branch.
This is useful when you want to inspect the exact patch before creating the new commit or when you do not want to preserve the original commit hash on the new branch.
What Not To Do
Avoid trying to isolate one commit by force-pushing a branch that still contains unrelated local history. That usually makes review harder and increases the risk of rewriting shared history unnecessarily.
Also avoid manually copying changed files into another working tree without preserving traceability. Even if that works technically, it makes later auditing and backporting harder than necessary.
Preserve Traceability in the Pull Request
When you move a commit this way, document the source commit hash and source branch in the pull request or release notes. That gives reviewers and future maintainers a clean link back to the original context.
A good note usually includes:
- original commit SHA
- original branch name
- whether the change was cherry-picked or patch-applied
- what tests were rerun on the isolated branch
Common Pitfalls
The biggest mistake is assuming Git has a clean “push just this commit” command for branch-based workflows. Another is cherry-picking a commit without noticing that it depends on earlier work. Developers also skip verification and then discover that their supposedly isolated branch still contains unrelated changes.
Summary
- Git pushes branch tips, not arbitrary commits detached from history.
- To send one change, create a clean branch from the remote base and
cherry-pickthe desired commit. - Verify the resulting branch before pushing so unrelated work does not slip in.
- Include prerequisite commits only when the chosen commit is not truly standalone.
- Keep the original commit SHA in your review notes so the isolated change stays traceable.
Related reading
- How can I push my existing Git repository to Team Foundation Service
- How can I push to my fork from a clone of the original repo?
- How can I put a database under git version control?
- How can I reconcile detached HEAD with master/origin?
- How can I recover a lost commit in Git?
- How can I remove a Git branch locally?
- How can I remove a GitLab project?
- How can I remove an entry in global configuration with git config?
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseNo course covers this one yet
Basis Lab writes one for you from a sentence about what you want to be able to do, then teaches it and checks you understood. Your first course is free.
Build my courseInterview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.