DEV Community

Cover image for Git Clone a Branch
Sarah Lean 🏴󠁧󠁒
Sarah Lean 🏴󠁧󠁒

Posted on β€’ Originally published at techielass.com

2 1

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 https://github.com/weeyin83/WorkingRepo.git

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 https://github.com/weeyin83/WorkingRepo.git
Enter fullscreen mode Exit fullscreen mode

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. πŸ‘

Neon image

Build better on Postgres with AI-Assisted Development Practices

Compare top AI coding tools like Cursor and Windsurf with Neon's database integration. Generate synthetic data and manage databases with natural language.

Read more β†’

Top comments (0)

Jetbrains image

Is Your CI/CD Server a Prime Target for Attack?

57% of organizations have suffered from a security incident related to DevOps toolchain exposures. It makes senseβ€”CI/CD servers have access to source code, a highly valuable asset. Is yours secure? Check out nine practical tips to protect your CI/CD.

Learn more

πŸ‘‹ Kindness is contagious

Engage with a wealth of insights in this thoughtful article, valued within the supportive DEV Community. Coders of every background are welcome to join in and add to our collective wisdom.

A sincere "thank you" often brightens someone’s day. Share your gratitude in the comments below!

On DEV, the act of sharing knowledge eases our journey and fortifies our community ties. Found value in this? A quick thank you to the author can make a significant impact.

Okay