Git
Version Control
Push Specific Commit
Git Commands
Remote Repository

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.

Browse interview questions

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:

  1. start from the target base branch
  2. copy the wanted commit
  3. 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.

bash
1git fetch origin
2git switch -c hotfix-only origin/main
3git cherry-pick COMMIT_SHA
4git push -u origin hotfix-only

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.

bash
git log --oneline origin/main..HEAD
git diff --stat origin/main...HEAD

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:

  1. identify the minimum prerequisite commits
  2. cherry-pick those in dependency order
  3. run tests after each step
bash
git cherry-pick DEPENDENCY_SHA
git cherry-pick COMMIT_SHA

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.

bash
1git format-patch -1 COMMIT_SHA --stdout > fix.patch
2
3git switch -c hotfix-only origin/main
4git apply --index fix.patch
5git commit -m "Apply isolated fix"

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:

  1. original commit SHA
  2. original branch name
  3. whether the change was cherry-picked or patch-applied
  4. 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-pick the 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.

Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Basis Lab
No 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 course
Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions