Skip to content
Fix Code Error

How do I clone a specific Git branch?

March 13, 2021 by Code Error
Posted By: Anonymous

Git clone will behave copying remote current working branch into local.

Is there any way to clone a specific branch by myself without switching branches on the remote repository?

Solution

git clone --single-branch --branch <branchname> <remote-repo>

The --single-branch option is valid from version 1.7.10 and later.

Please see also the other answer which many people prefer.

You may also want to make sure you understand the difference. And the difference is: by invoking git clone --branch <branchname> url you’re fetching all the branches and checking out one. That may, for instance, mean that your repository has a 5kB documentation or wiki branch and 5GB data branch. And whenever you want to edit your frontpage, you may end up cloning 5GB of data.

Again, that is not to say git clone --branch is not the way to accomplish that, it’s just that it’s not always what you want to accomplish, when you’re asking about cloning a specific branch.

Answered By: Anonymous

Related Articles

  • Form field border-radius is not working only on the…
  • Trouble with boxes appearing/hiding based on selection
  • Git - Pushing code to two remotes
  • Why do I have to "git push --set-upstream origin "?
  • Why call git branch --unset-upstream to fixup?
  • Why do git fetch origin and git fetch : behave differently?
  • Generating a drop down list of timezones with PHP
  • Checkout another branch when there are uncommitted…
  • Git Using Remote Branch
  • How to fetch all Git branches
  • Why does git perform fast-forward merges by default?
  • Retrieve specific commit from a remote Git repository
  • What's the difference between git clone --mirror and…
  • Various ways to remove local Git changes
  • Difference between git checkout --track…
  • git pull while not in a git directory
  • What is a tracking branch?
  • What are the differences between git remote prune,…
  • How do SO_REUSEADDR and SO_REUSEPORT differ?
  • How to track untracked content?
  • Git workflow and rebase vs merge questions
  • How to recover stashed uncommitted changes
  • How do I clone a single branch in Git?
  • How do I make a Git commit in the past?
  • How to clone ('fork') your own personal GitHub repo…
  • What is "git remote add ..." and "git push origin master"?
  • Git submodule update
  • Change a Git remote HEAD to point to something…
  • How can I find the location of origin/master in git,…
  • Your configuration specifies to merge with the from…
  • Is it safe to shallow clone with --depth 1, create…
  • Check if pull needed in Git
  • Why did my Git repo enter a detached HEAD state?
  • Setting up and using Meld as your git difftool and mergetool
  • How can I delete all Git branches which have been merged?
  • Adding Google Translate to a web site
  • How do I delete a Git branch locally and remotely?
  • How does origin/HEAD get set?
  • What exactly does the "u" do? "git push -u origin…
  • In plain English, what does "git reset" do?
  • How to pull in changes from skeleton sub-repository…
  • What's the difference between HEAD^ and HEAD~ in Git?
  • Does "git fetch --tags" include "git fetch"?
  • “tag already exists in the remote" error after…
  • Detach (move) subdirectory into separate Git repository
  • git lfs push to github failure on Ubuntu 18.04
  • Merge, update, and pull Git branches without using checkouts
  • Why does Git say my master branch is "already up to…
  • Why am I getting a "401 Unauthorized" error in Maven?
  • How do you stop tracking a remote branch in Git?
  • What are the undocumented features and limitations…
  • What is git tag, How to create tags & How to…
  • What's the difference between "git reset" and "git…
  • Why does git status show branch is up-to-date when…
  • Git merge with force overwrite
  • How to fix Git error: object file is empty?
  • npm ERR! fetch failed status code 502
  • Homebrew install specific version of formula?
  • Git push won't do anything (everything up-to-date)
  • How to backup a local Git repository?
  • git remote prune – didn't show as many pruned…
  • How to remove MySQL completely with config and…
  • How do I rename both a Git local and remote branch name?
  • How do I 'overwrite', rather than 'merge', a branch…
  • Why does git say "Pull is not possible because you…
  • How do I install Java on Mac OSX allowing version switching?
  • Remove tracking branches no longer on remote
  • Git fetch remote branch
  • Why is Git better than Subversion?
  • Push git commits & tags simultaneously
  • Git: Create a branch from unstaged/uncommitted…
  • How to create the branch from specific commit in…
  • Remote branch is not showing up in "git branch -r"
  • hide select options using only css
  • How can I switch to another branch in git?
  • How to list branches that contain a given commit?
  • Git push error: "origin does not appear to be a git…
  • Push on GIT and Bitbucket
  • Recalculate merge conflicts (ie. how to generate…
  • How do you get git to always pull from a specific branch?
  • Reference — What does this symbol mean in PHP?
  • Ukkonen's suffix tree algorithm in plain English
  • Calculate the mean by group
  • Importing a GitHub project into Eclipse
  • How to retrieve a single file from a specific…
  • How to configure Git post commit hook
  • error: pathspec 'test-branch' did not match any…
  • git push says "everything up-to-date" even though I…
  • How can I get a list of locally installed Python modules?
  • What are the differences between git branch, fork,…
  • Git push: "fatal 'origin' does not appear to be a…
  • Delete all local git branches
  • Why does C++ code for testing the Collatz conjecture…
  • Is it possible to use pip to install a package from…
  • Egit rejected non-fast-forward
  • "Non-resolvable parent POM: Could not transfer…
  • Git: Merge a Remote branch locally
  • Identifying and solving…
  • unable to deploy next js to azure
  • ExpressJS How to structure an application?

Disclaimer: This content is shared under creative common license cc-by-sa 3.0. It is generated from StackExchange Website Network.

Post navigation

Previous Post:

How to replace all occurrences of a string in Javascript?

Next Post:

How to execute a program or call a system command from Python

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

.net ajax android angular arrays aurelia backbone.js bash c++ css dataframe ember-data ember.js excel git html ios java javascript jquery json laravel linux list mysql next.js node.js pandas php polymer polymer-1.0 python python-3.x r reactjs regex sql sql-server string svelte typescript vue-component vue.js vuejs2 vuetify.js

  • you shouldn’t need to use z-index
  • No column in target database, but getting “The schema update is terminating because data loss might occur”
  • Angular – expected call-signature: ‘changePassword’ to have a typedeftslint(typedef)
  • trying to implement NativeAdFactory imports deprecated method by default in flutter java project
  • What should I use to get an attribute out of my foreign table in Laravel?
© 2022 Fix Code Error