Fix Missing Git Branches - Bench get-app Cloned Only One Branch

git shows only one branch

Why Git Fetches Only One Branch (Single-Branch Clone Explained)

🚨 Help! I Cloned a Repository but I Can Only See One Branch

You open a repository on GitHub.

You clearly see:

  • 20+ branches
  • Active pull requests
  • Developers working on develop, feature-x, ui-fix, etc.

You clone it locally.

Then you run:

git branch -a

And you see…

* version-16
  remotes/upstream/HEAD -> upstream/version-16
  remotes/upstream/version-16

That’s it.

No develop. No feature branches. Nothing.

It feels like Git deleted everything.

It didn’t.

Let’s understand what actually happened.


🧠 First: What’s Supposed to Happen When You Clone?

When you clone a repository, Git normally:

  1. Downloads all commit history
  2. Downloads all branch references
  3. Lets you switch between them

But some tools (like bench get-app in the Frappe ecosystem) optimize cloning to make it faster.

They tell Git:

“Download only the default branch. Ignore the rest.”

This is called a single-branch clone.

So Git is not broken. It’s just doing exactly what it was told.


🔍 Step 1: Confirm the Problem (Don’t Fix Blindly)

Before running any fix, let’s verify.

Run this:

git config --get remote.upstream.fetch

(If your remote is named origin, replace upstream with origin.)

If you see this:

+refs/heads/version-16:refs/remotes/upstream/version-16

That means:

“Only fetch version-16 branch.”

This confirms you are in single-branch mode.


If you see this instead:

+refs/heads/*:refs/remotes/upstream/*

Then your config is correct, and the issue is something else.


🧠 What Is That Weird String?

Let’s break this down in human language.

+refs/heads/version-16:refs/remotes/upstream/version-16

It means:

PartMeaning
refs/heads/version-16Only download this branch from GitHub
:Map from server to local
refs/remotes/upstream/version-16Store it locally under upstream/version-16

There is no wildcard (*). So Git ignores all other branches.


🛠 Step 2: Fix It Properly

Now that we understand the problem, let’s fix it.

We need to tell Git:

“Stop being specific. Fetch ALL branches.”

Run:

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

What changed?

We replaced:

version-16

With:

*

That star means:

“Everything.”


📥 Step 3: Actually Download the Branches

Updating config doesn’t download anything yet.

Now run:

git fetch --all

Now Git will download all remote branches.

You should see output like:

* [new branch] develop -> upstream/develop
* [new branch] feature-login -> upstream/feature-login
* [new branch] ui-fix -> upstream/ui-fix

🎉 Step 4: Confirm It Worked

Run:

git branch -a

Now you’ll see:

remotes/upstream/develop
remotes/upstream/feature-login
remotes/upstream/ui-fix

You can now create a local branch:

git checkout -b develop upstream/develop

And you’re good to go.


⚠ Why This Happens (Especially in Frappe Projects)

Tools like:

  • bench get-app
  • Some CI pipelines
  • Some Docker setups

Use optimized cloning like:

git clone --single-branch

This makes cloning faster and lighter — especially for large repos.

But when you need another branch, you suddenly hit this wall.


🧩 Important: This Is NOT the Same as a Shallow Clone

You might have seen another issue where Git downloads only limited commit history.

That’s called a shallow clone (--depth 1).

That is a different problem.

This article fixes missing branches. Shallow clone fixes missing history.

Two different layers of Git.


🧘 Mental Model (So You Don’t Panic Next Time)

Think of a Git repository like this:

  • 📚 Commit history = The story
  • 🌳 Branches = The bookmarks

A shallow clone hides part of the story.

A single-branch clone hides the other bookmarks.

Now you know how to restore the bookmarks.


🏁 Final Summary (Beginner-Friendly Version)

If git branch -a shows only one branch:

  1. Check fetch config:

    git config --get remote.upstream.fetch
    
  2. If it targets a single branch, update it:

    git config remote.upstream.fetch "+refs/heads/*:refs/remotes/upstream/*"
    
  3. Fetch:

    git fetch --all
    

Done.

Related posts