Skip to content

Commit bfd67e1

Browse files
committed
Add new git cherry pick article
1 parent a5bf7ec commit bfd67e1

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
title: Cherry-pick an unreachable GitHub commit
3+
shortTitle: Cherry-pick unreachable commit
4+
language: git
5+
tags: [commit,branch]
6+
cover: laptop-bronze-mug
7+
excerpt: Have you ever needed to cherry pick a GitHub commit that does not belong to any branch on this repository? Here's an easy way to do it.
8+
listed: true
9+
dateModified: 2026-04-03
10+
---
11+
12+
I recently came across an odd problem on a branch I was working on. There was **a commit that was only on GitHub**, that I needed to [cherry-pick](/git/s/pick-commits) locally, but it had the following message:
13+
14+
> This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
15+
16+
I wasn't entirely sure what that meant, but I knew that **the commit wasn't part of a branch**, therefore I had a general idea that plain `git cherry-pick <commit>` wouldn't work. And, obviously it did not!
17+
18+
I decided, instead of looking it up on the internet, to ask Copilot about it, to save some time and to put my tokens to good use. And, to nobody's surprise, I got a pretty good answer. Simply put, I have to **explicitly fetch the commit from the remote** (i.e. GitHub), and then I can cherry-pick it.
19+
20+
```shell
21+
# Syntax: git fetch <remote> <commit>
22+
# git cherry-pick <commit>
23+
24+
# Fetch the commit directly by SHA first
25+
git fetch origin 8776de5
26+
27+
# Cherry pick as usual
28+
git cherry-pick 8776de5
29+
```
30+
31+
The explanation is that the commit object exists, but it is **not reachable from any branch/tag you can fetch from your current remotes**. So plain cherry-pick fails because your local repo does not have that commit object yet.
32+
33+
> [!NOTE]
34+
>
35+
> If you had **created this commit locally**, it would be part of your git tree and you could cherry-pick it without fetching. But since it was only on the remote and not part of any branch, you need to fetch it first to make it available in your local repository.
36+

0 commit comments

Comments
 (0)