TrentWoodbury
TrentWoodbury

Reputation: 911

How to clone a subset of git branches

I am cloning from a repo with >1000 branches. I want to clone the master branch and a single feature branch (and nothing else).

I know I can clone just the feature branch by running

git clone git@url_for_git_repo.com --single-branch --branch feature_branch_name

but then I don't have access to the master branch. How can I add the master branch to my local repo now?

Upvotes: 0

Views: 266

Answers (2)

torek
torek

Reputation: 489628

Use git remote to add individual branches. For instance, if you cloned the single branch branch1 but really want five remote-tracking names for origin/master, origin/branch1, origin/branch2, ..., origin/branch4:

git remote set-branches --add origin master branch2 branch3 branch4

would do the trick.

(You can also manually edit the .git/config file, or run git config --edit, if you're comfortable manipulating the configuration file that way.)

Note that set-branches --add is very different from plain add; the latter adds an additional remote, rather than adding branches to one particular single-branch remote. Also, set-branches without --add means discard the existing remote-tracking names, and change to single-branch mode for the specified branches.

(It's kind of unfortunate that Git uses the word remote to mean one thing, and remote-tracking branch or what I call remote-tracking name to mean another quite different thing. It gets very confusing.)

Upvotes: 3

eftshift0
eftshift0

Reputation: 30297

I guess you could ask for it specifically with

git fetch origin master

Upvotes: 1

Related Questions