DEV Community

Cover image for I Forked a Repo but Only Got the `main` Branch - Here's What I Did
Werliton Silva
Werliton Silva

Posted on

I Forked a Repo but Only Got the `main` Branch - Here's What I Did

So here's what happened...

I forked a project on GitHub because I wanted to contribute to one of its features.

But when I opened my fork - boom 💥 - only the main branch was there. All the other branches from the original repo? Gone.

At first, I thought something went wrong with the fork. But nope - that’s just how GitHub works.


🤔 The Problem

When you fork a repo on GitHub, it only brings the default branch (usually main or master).

It does not copy over the other branches.

If the original repo had branches like:

  • feature/login
  • bugfix/style
  • refactor/api

You won’t see them in your fork.

But don't worry - they’re still there, just not in your copy… yet.


✅ The Solution

Here’s how I pulled the missing branches into my fork:

1. I added the original repo as a remote

git remote add upstream https://github.com/original-user/original-repo.git
Enter fullscreen mode Exit fullscreen mode

Replace that URL with the actual repo you forked from.

2. Then I fetched all the branches from the original repo

git fetch upstream
Enter fullscreen mode Exit fullscreen mode

Now I could see all the remote branches by running:

git branch -r
Enter fullscreen mode Exit fullscreen mode

I saw branches like:

upstream/feature/login
upstream/bugfix/style
Enter fullscreen mode Exit fullscreen mode

3. I checked out the one I wanted

Let’s say I needed the feature/login branch:

git checkout -b feature/login upstream/feature/login
Enter fullscreen mode Exit fullscreen mode

Boom - now I had that branch locally.

4. (Optional) I pushed it to my fork on GitHub

If I wanted to work on it and push it to my forked repo:

git push origin feature/login
Enter fullscreen mode Exit fullscreen mode

Now it exists on my GitHub too.


🎉 Problem Solved!

ilovy

So if you ever fork a repo and wonder,

"Where are the other branches?"

They’re not missing - you just need to fetch them manually.

Hope this helps someone out there! ✌️


#git #github #devto #webdev #beginners

Top comments (0)