Git clone a branch

Have you ever just wanted to clone a certain branch from your GitHub repository to work on your local machine and don’t want the other 300-odd branches that the repository might have?

Well stick around and I’ll show you how to do that!

Does git clone clone all branches?

Yes it will, which can be useful if you are working across all the branches but it can also lead to confusion and commits happening on the wrong branch.

Clone a specific branch

I have several branches in one of my GitHub repositories, but I just want a specific branch so I can work on that and don’t need the others.

The first I do is grab the URL for the GitHub repository, in this case it’s

The first thing I do is open up my Windows Terminal, you can use a command prompt window or even the terminal inside Visual Studio Code. Whatever is your preference.

I now type in the command:

git clone -b sarahmonday

This specifies that I want to clone the branch “sarahmonday” within the WorkingRepo repository.

Check which branches you have on your local machine

To double check what branches you have on your machine you can navigate to the new folder you have on your machine and run:

It should just list the branch you’ve just cloned. 👍

If you’ve found this tip useful be sure to check out my other Git tips.

Originally published at on January 11, 2022.




Community Speaker — Lifelong Learner — Founder of the Glasgow Azure User Group

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Chhjose Apps For Files On Mac

IBSIMU simulation package in a Docker container

Detaching Cloudant Attachments to Object Storage with Serverless Functions

Day 9: 100 Days of Code — 7–13–2019

Micronaut Coherence 1.0.0 Milestone 1 Released

Housekeepers Hire With Us in Ajax ON

Coding vs Computational Thinking

Students are Why We Do What We Do

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Sarah Lean

Sarah Lean

Community Speaker — Lifelong Learner — Founder of the Glasgow Azure User Group

More from Medium

Submodules That Don’t Suck

How to Build a Docker Image For Running a Cron Job

Text Translation using Powershell

Revert those changes in Git