Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
411 views
in Technique[技术] by (71.8m points)

git - How do I "undo" a --single-branch clone?

I cloned a repo using the

git clone -b <branch name> --single-branch <github url> <target directory>

This cloned ONLY this branch, but now I want to switch to the master and other branches. Is there any way besides clearing it out and starting over to clone the rest of the repo that I can undo the --single-branch preference?

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can tell Git to pull all branches like this:

git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
git fetch origin

If you look in .git/config, it'll look something like this:

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
    ignorecase = true
    precomposeunicode = false
[remote "origin"]
    url = https://github.com/owner/repo.git
    fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
    remote = origin
    merge = refs/heads/master
    rebase = true

I compared this to a full clone, and saw that the only difference was the "fetch" under [remote "origin"].

Note: I'm running Git version 1.8.2. The config options may have changed if you're running an older version of Git. If my commands don't work, then I'd recommend looking through .git/config to see if you can see something similar.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...