git 克隆存储库而不将其设为远程源
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2248994/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Cloning a repository without making it the origin remote
提问by Andrew Grimm
I'm cloning a git repository from a computer that's going to be wiped.
我正在从将要被擦除的计算机上克隆一个 git 存储库。
Is it possible to clone a repository without making the original repository origin/master
? Or do I need to clone it, and then delete the remote branch (which is done with git remote rm origin
)?
是否可以在不制作原始存储库的情况下克隆存储库origin/master
?还是我需要克隆它,然后删除远程分支(用 完成git remote rm origin
)?
Edit: The repository has only one branch, and no tags.
编辑:存储库只有一个分支,没有标签。
采纳答案by Jess Bowers
It is not necessary to make the original repository the "origin" remote to clone the master branch.
没有必要使原始存储库成为克隆主分支的“源”远程。
On the new machine, create a new repository:
在新机器上,创建一个新的存储库:
git init foo
Then pull the old repository into the new one, without creating a remote:
然后将旧存储库拉入新存储库,无需创建远程:
cd foo
git pull <reference to old repository>
However, it should be noted that the easiest way to save off a repository would be to just zip the repository's directory up and move the files to a new machine. That will preserve any and all remotes, tags, etc.
但是,应该注意的是,保存存储库的最简单方法是将存储库的目录压缩并将文件移动到新机器上。这将保留任何和所有遥控器、标签等。
As noted below, when copying the repository, be careful when going from case-sensitive file systems (eg. Linux, Mac, NTFS) to non-case sensitive (eg. Fat32).
如下所述,在复制存储库时,从区分大小写的文件系统(例如 Linux、Mac、NTFS)到不区分大小写的文件系统(例如 Fat32)时要小心。
回答by Jakub Nar?bski
First, you can use --origin <name>
option of git clone
首先,您可以使用--origin <name>
选项git clone
--origin <name>, -o <name>
Instead of using the remote name originto keep track of the upstream repository, use <name>.
--origin <名称>, -o <名称>
不要使用远程名称来源来跟踪上游存储库,而是使用<name>。
Second, you can use git remote add
to add repository to fetch from to existing repository (so you can use git init
, then git remote add <name> <url>
).
其次,您可以使用git remote add
添加存储库以从现有存储库中提取(因此您可以使用git init
, then git remote add <name> <url>
)。
If you want to create a mirror of repository, with refs/heads/*
going into refs/heads/*
in clone, you can init
repository, setup appropriate refspec, and then fetch
...
如果要创建存储库的镜像,refs/heads/*
进入refs/heads/*
克隆,您可以init
存储库,设置适当的 refspec,然后fetch
...
Or you can use git clone --mirror
, which should answer current version of OP question.
或者您可以使用git clone --mirror
,它应该回答当前版本的 OP 问题。
This would however not preserve configuration (including remotes), worktree state, reflogs, etc. For this you would need to copy repository whole, as Jess Bowers said.
然而,这不会保留配置(包括远程)、工作树状态、引用日志等。为此,您需要复制整个存储库,正如Jess Bowers 所说。
回答by VonC
The general way to handle such a trasfer would be git bundle
. See Backup of github repo.
处理这种传输的一般方法是git bundle
. 请参阅github repo 的备份。
From your second (new) desktop:
从您的第二个(新)桌面:
git bundle create file:///\oldDesktop/share/myGitRepo --all
to create one local file from which you will be able to clone a local git repo.
创建一个本地文件,您可以从中克隆本地 git 存储库。
Note:the file:///
protocol will support UNC (Universal Naming Convention) Windows path, with the rest of the path using '/
' instead of '\
'. See Git on a Windows Lan.
注:该file:///
协议将支持UNC(通用命名约定)的Windows路径,使用“的路径的其余部分/
”而不是“ \
”。请参阅Windows Lan 上的 Git。
回答by ebneter
Does the remote repo have more branches than just master? It's trickier if it does; you need to make local copies of all of the branches as well because when you delete the remote, all the remote/origin branches will go away. (I just tried it!)
远程仓库是否有比 master 更多的分支?如果是这样就更棘手了;您还需要制作所有分支的本地副本,因为当您删除远程时,所有远程/源分支都会消失。(我刚试过!)
So, you can do something like this:
所以,你可以做这样的事情:
git clone <remote_url>
cd <repo>
for b in $(git branch -r | grep -v HEAD | grep -v master);do
git branch $(basename $b) $b
done
git remote rm origin
Of course, as Jess Bowers said, it's even easier to just tar or zip it up and move the files, if you have access to the machine to do that.
当然,正如 Jess Bowers 所说,如果您可以访问机器来执行此操作,只需将其压缩或压缩并移动文件就更容易了。
You can also just make a bare clone:
您也可以制作一个裸克隆:
git clone --bare <remote_url>
and then make new clones from that.
然后从中制作新的克隆。
回答by tr4656
I do believe you would need to delete the remote branch.
我相信您需要删除远程分支。