惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Martin Fowler
Martin Fowler
大猫的无限游戏
大猫的无限游戏
J
Java Code Geeks
罗磊的独立博客
雷峰网
雷峰网
G
Google Developers Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
爱范儿
爱范儿
B
Blog RSS Feed
腾讯CDC
Apple Machine Learning Research
Apple Machine Learning Research
D
Docker
Recent Announcements
Recent Announcements
T
Tailwind CSS Blog
博客园 - 聂微东
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Vercel News
Vercel News
小众软件
小众软件
人人都是产品经理
人人都是产品经理
云风的 BLOG
云风的 BLOG
IT之家
IT之家
Blog — PlanetScale
Blog — PlanetScale
I
InfoQ
S
SegmentFault 最新的问题

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
Git Branch Exists on Remote But Won't Show Locally
Ryan Carter · 2026-04-29 · via DEV Community

Ryan Carter

If a git branch shows up on the remote but git branch -r doesn't list it locally, your fetch refspec is almost always scoped to a single branch instead of all branches. Fix it with one config change: git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*" followed by git fetch origin --prune. This commonly happens after shallow clones, certain CI checkouts, and clones run with --single-branch.

The full diagnosis takes about two minutes — start by confirming the branch exists on the remote, then walk through the three fixes below in order.

Confirm the branch actually exists on the remote

First, bypass your local cache entirely and ask the remote directly:

git ls-remote origin

Enter fullscreen mode Exit fullscreen mode

If your branch shows up here but not in git branch -r, your local remote-tracking refs are stale or incorrectly scoped. That's the problem — and it's fixable.

If it doesn't show up here either, the issue is permissions or a wrong remote URL. Check with git remote -v and make sure origin points where you think it does.

Fix 1: Fetch with prune

The simplest thing to try first:

git fetch origin --prune

Enter fullscreen mode Exit fullscreen mode

The --prune flag removes stale remote-tracking refs and re-syncs. Sometimes that's all it takes.

Fix 2: Fetch the specific branch by name

If a general fetch isn't picking it up, fetching by name often forces it:

git fetch origin your-branch-name

Enter fullscreen mode Exit fullscreen mode

Fix 3: Check your fetch refspec

This is the most common root cause when the above don't work. Check your git config:

cat .git/config

Enter fullscreen mode Exit fullscreen mode

Look at the [remote "origin"] section. It should look like this:

[remote "origin"]
    url = git@github.com:you/your-repo.git
    fetch = +refs/heads/*:refs/remotes/origin/*

Enter fullscreen mode Exit fullscreen mode

The fetch line is the refspec — it tells git which branches to track. The * wildcard means "all branches."

If yours looks like this instead:

fetch = +refs/heads/main:refs/remotes/origin/main

Enter fullscreen mode Exit fullscreen mode

That's your problem. The refspec is scoped to a single branch, so git is only tracking main and ignoring everything else. This happens with shallow clones, some CI checkout configurations, and certain git clone flags.

Fix it by updating the refspec:

git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
git fetch origin

Enter fullscreen mode Exit fullscreen mode

After that, git branch -r should show all remote branches.

Quick reference

Symptom Likely cause Fix
Branch in ls-remote but not branch -r Stale or scoped refspec Update refspec, re-fetch
Branch missing after git fetch Stale tracking refs git fetch origin --prune
Branch missing entirely from ls-remote Wrong remote URL or permissions Check git remote -v

The ls-remote check is always the right first step — it tells you immediately whether the problem is on the remote side or local side, which cuts the diagnosis in half.

FAQ

Why does git fetch not pick up the new branch?

Either your remote-tracking refs are stale (fix with --prune), or your fetch refspec is scoped to a single branch (the most common cause when --prune doesn't help). The refspec lives in .git/config under [remote "origin"].

What is a fetch refspec and why does it matter?

A refspec tells git which remote refs to download and where to store them locally. The default +refs/heads/*:refs/remotes/origin/* means "fetch every branch on the remote into origin/* locally." If yours is scoped to a specific branch (e.g. refs/heads/main:refs/remotes/origin/main), git will only ever track that one branch.

How did my refspec get scoped to a single branch?

Common causes: cloning with --single-branch, cloning with --branch <name> plus --single-branch, GitHub Actions checkouts that use fetch-depth: 1 and a specific ref, and some Dependabot/CI tools that explicitly scope the refspec to save bandwidth.

Is git fetch --all --prune the same as fixing the refspec?

No. --all fetches from every configured remote (relevant if you have multiple), and --prune removes stale remote-tracking refs — but neither expands a refspec that's scoped to a single branch. You still have to fix the refspec itself.

Will fixing the refspec break anything?

No. It just tells git to track all branches instead of one. You won't lose history, refs, or local branches. The next git fetch origin will pull down all the previously-ignored remote branches.