Elena' s AI Blog

I have cloned my git repository and landed on main. How to get your branch

03 Oct 2025 / 2 minutes to read

Elena Daehnhardt


DALL·E / OpenAI’s image model inside ChatGPT 5.0: A flat-style digital illustration depicts a software developer transitioning from the 'main' branch to the 'dev' branch using the command ‘git fetch origin’, displayed in a clean, digital flat art style with a light beige background. The developer, depicted with black hair, glasses, and casual attire, steps from a dark grey platform labelled ‘main’ towards a glowing turquoise ‘dev’ platform, while a teleportation effect reinforces the shift between the two branches.


Introduction

Cloning a repository is exciting — new code, new adventure.
But sometimes Git drops you straight onto main when you really wanted that shiny dev branch.

      Remote (origin)          Local
    ------------------      ------------
    origin/main             main  ← default after clone
    origin/dev      ---->   dev   ← your new branch

No worries. Here’s the quick rescue plan.

The critical step

First, tell Git to look for other branches on the remote:

git fetch origin

👉 This is the magic unlock: it updates your local repo with all branches that exist on the remote (like dev, feature-x, etc.). Without it, your machine doesn’t even know those branches are there.

Why git fetch origin matters?

  • Cloning only grabs the default branch (usually main or master).
  • fetch downloads branch info and commits without changing your files.
  • After fetch, you can switch safely to any remote branch.

Jump to your branch

Now switch to the branch you want — for example dev:

git switch dev

(Older style: git checkout -b dev origin/dev — works the same way.)

Pull the latest updates just to be sure:

git pull

Done. No tears, no confusion — just smooth Git moves. 🚀

💡 Quick tip: If you’ve made changes but haven’t committed them yet, save them before switching:

git stash

Then switch branches and bring your changes back with:

git stash pop

Wrap-up

That’s it — a simple way to jump from main to where the real work lives. Remember: git fetch origin is your secret handshake to see all remote branches. Next time you clone and panic, you’ll know exactly what to do :)

Did you like this post? Please let me know if you have any comments or suggestions.

Git posts that might be interesting for you




desktop bg dark

About Elena

Elena, a PhD in Computer Science, simplifies AI concepts and helps you use machine learning.

Citation
Elena Daehnhardt. (2025) 'I have cloned my git repository and landed on main. How to get your branch', daehnhardt.com, 03 October 2025. Available at: https://daehnhardt.com/blog/2025/10/03/i-have-cloned-my-git-repository-and-landed-on-main-how-to-get-your-branch/
All Posts