I’m trying to download a particular branch called development
from a GitHub repository instead of the default main branch.
When I look at the project documentation, they show the same clone command for both the main branch and the development branch:
git clone --depth 1 https://github.com/username/projectname.git local/folder/project
This command seems to pull the main branch by default. What parameter or flag do I need to add to this git clone command to specifically target the development branch instead of getting the main one? I want to make sure I get the right version of the code for my project.
there’s also a way to just clone the whole repo, then switch to the branch you want. sometimes the --branch flag acts up with certain networks. run git clone https://github.com/username/projectname.git
and then git checkout development
in the folder. it might take longer, but it’s more dependable.
The -b
shorthand works just as well if you want to type less. Your command becomes git clone --depth 1 -b development https://github.com/username/projectname.git local/folder/project
. This is super handy when repos have multiple active branches - saves you from cloning the default branch then switching later. Just heads up: if the development branch doesn’t exist remotely, the clone will fail. Double-check the branch name in the repo’s branch list on GitHub first.
Here’s another approach that works great: git clone --single-branch --branch development https://github.com/username/projectname.git local/folder/project
. The --single-branch
flag grabs just the development branch instead of every remote branch - super helpful for big repos. I use this all the time when dealing with repos that have tons of feature branches. Keeps things clean and clones way faster. You can always add more remote branches later with git remote set-branches
if you need them. This has saved me so much bandwidth on projects with crazy branch histories.