我是GIT的新手 我有一个远程git存储库。我想创建一个与远程相同的本地存储库(所有分支和标签与远程相同) 我想在我的本地存储库上测试我的git命令然后我可以将它推送到远程 很多帖子我看过人们告诉他们做克隆或镜子的地方,但这对我不起作用。
local rep <---> remote rep
-> all branches <===> -> all branches
-> all tags <===> -> all tags
现在我想将我的本地存储库用作服务器
git clone "D:\localrep\"
应具备所有功能(分支,标记和历史记录)作为远程服务器
答案 0 :(得分:0)
正如我在评论中已经告诉过你的那样,git clone
不会(据我所知)在本地为你自动创建所有分支。
您可以使用git branch
检查本地存储库中的所有分支。
$ git branch
* master
这里这个git存储库只有一个分支:master分支。如果您使用git clone
克隆它,它将会是这样的
如果要检查本地存储库知道哪些远程分支存在,则必须运行git branch -a
。远程分支将采用以下形式:
$ git branch -a
* master
remotes/origin/HEAD
remotes/origin/master
remotes/origin/other_branch
remotes/origin/branch_two
带有“remotes /”的是远程存储库中的分支。所以在这里你看到远程存储库origin
拥有3个分支(带有remotes/origin/<branch_name>
的行):master,other_branch和branch_two。
如果您想在本地使用它们,则必须使用git checkout -b
创建它们,例如:
git checkout -b <new_local_branch> <remote_repository>/<remote_branch_name>
您将<new_local_branch>
替换为您希望其在本地存储库中拥有的名称,并<remote_repository>/<remote_branch_name>
替换remotes/
输出中git branch -a
之后的名称。
例如,要创建分支other_branch
localy作为远程分支的副本,您只需使用相同的名称:
git checkout -b other_branch origin/other_branch
然后您会看到git branch
的输出
$ git branch
master
* other_branch
如果您想自动执行此操作,您可以根据git branch -a
的输出创建一个命令,如下所示:
git branch -a | grep "remotes/origin" | egrep -v "origin/(master|HEAD)$" | \
sed "s:remotes/\([^/]\+/\(.\+\)\)$:git checkout -b \2 \1:" | bash
除了master-branch之外,这个将在本地创建所有分支。如果有其他分支则不必创建在“()”之间的egrep的正则表达式中添加它们,用“|”分隔