Git克隆存储库位于特定文件夹中,但保留默认文件夹名称 [英] Git clone repository in a specific folder but keep default folder name
问题描述
所以我使用的是git clone命令,但是当我尝试将存储库克隆到特定文件夹时,它不会像通常那样创建文件夹。
例如,当我像这样使用它时
git clone https://github.com/username/repositoryName。 git
它创建一个名为repositoryName的文件夹并将该存储库存储在其中。当我像这样使用它时
git clone https://github.com/username/repositoryName.git myFolderName
它不会创建该默认文件夹。它只是将其保存在myFolderName中。问题是我希望将其存储在该默认文件夹中,但我希望该默认文件夹位于myFolderName中。我无法使用mv命令,因为我不知道默认文件夹名称,并且我同时克隆了很多存储库。有任何想法吗?像这样:
##您在数组
中的链接声明-a arr =( https:// github .com / username / repositoryName https://github.com/username/repositoryName2)
##存放每个git仓库的文件夹
folder = myFolderName
##在 $ {arr [@]}中为i遍历数组
中的每个链接
do
##使用基本名从链接$ b $中提取文件夹名称b git clone $ i $ folder / $(basename $ i)
完成
产生以下git储存库:
myFolderName / repositoryName
myFolderName / repositoryName2
注意:您不需要添加 .git
在 git clone
的每个HTTPS链接的末尾。
如果出于某些原因需要包含 .git
,则可以使用以下方法删除它:
git clone $ i $ folder / $(基本名$ {i%。*})
So I'm using the git clone command but when I try to clone the repository into a specific folder it doesn't create a folder like it does normally. For example when I use it like this
git clone https://github.com/username/repositoryName.git
it creates a folder named repositoryName and stores the repository in there. When I'm using it like this
git clone https://github.com/username/repositoryName.git myFolderName
it doesn't create that default folder it would create. It just saves it in myFolderName. The thing is that I want it stored in that default folder but I want that default folder in myFolderName. I can't use mv command because I don't know the defaults folder name and I clone a lot of repositories at the same time. Any ideas?
Thanks in advance.
What about something like this:
## Your links in an array
declare -a arr=("https://github.com/username/repositoryName" "https://github.com/username/repositoryName2")
## Folder to store each of these git repos
folder=myFolderName
## Go through each link in array
for i in "${arr[@]}"
do
## Use basename to extract folder name from link
git clone $i $folder/$(basename $i)
done
Which will produce your following git repositories:
myFolderName/repositoryName
myFolderName/repositoryName2
Note: You don't need to add .git
at the end of each HTTPS link for git clone
.
If you need to include .git
for some reason, you can strip it with:
git clone $i $folder/$(basename ${i%.*})
这篇关于Git克隆存储库位于特定文件夹中,但保留默认文件夹名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!