How to Pull a Specific Commit from GitHub

In Git, it’s common to want just one specific commit from a remote repository—without pulling the entire branch. Whether you’re cherry-picking a hotfix or reviewing a past change, Git provides tools to fetch and apply specific commits efficiently.

In this blog, you’ll learn how to pull a specific commit from GitHub using git fetch and git cherry-pick.


✅ Prerequisites

Ensure you have:

  • Git installed on your system
  • Access to the remote repository (e.g., GitHub)
  • The commit hash (SHA) of the specific commit you want to pull

🔹 Step 1: Fetch Latest Commits from GitHub

Before selecting a specific commit, make sure your local repo is updated with the latest changes from the remote:

git fetch origin

This will update your local references without merging anything.


🔹 Step 2: Identify the Commit Hash

Find the commit hash (e.g., a1b2c3d4) on GitHub:

  • Navigate to the repo
  • Go to Commits
  • Copy the full or short SHA of the desired commit

🔹 Step 3: Cherry-Pick the Commit

Now apply that specific commit to your current branch:

git cherry-pick <commit-hash>

Example:

git cherry-pick a1b2c3d4

This copies the commit changes into your current branch without merging the entire branch.


🔁 Optional: Pull from a Specific Remote Branch First

If the commit is on a different remote branch, fetch that branch first:

git fetch origin feature-branch

Then cherry-pick the commit from that branch:

git cherry-pick <commit-hash>

🚫 Handling Cherry-Pick Conflicts

If you get a conflict while cherry-picking:

  1. Git will pause and show the conflict.
  2. Manually resolve the conflict in the affected file(s).
  3. After resolving, run:
git add .
git cherry-pick --continue

Or, to abort:

git cherry-pick --abort

✅ Summary

TaskCommand
Fetch remote commitsgit fetch origin
Cherry-pick a commitgit cherry-pick <commit-hash>
Abort cherry-pickgit cherry-pick --abort
Continue after conflict resolutiongit cherry-pick --continue

🚀 Final Thoughts

Pulling a specific commit from GitHub is a powerful Git skill—perfect for hotfixes, code reviews, and precise version control. Just remember that cherry-picking rewrites history, so it’s best used on local or feature branches unless you’re confident in the changes.

Sharing Is Caring:

Leave a Comment