git clone - 默认情况下如何在文件夹名称中保留.git

时间:2011-04-08 13:41:18

标签: git

来自man git-clone:

   <directory>
       The name of a new directory to clone into. The "humanish" part of the source repository
       is used if no directory is explicitly given (repo for /path/to/repo.git and foo for
       host.xz:foo/.git). Cloning into an existing directory is only allowed if the directory is
       empty.

我希望我的git-clone默认显示名为“project.git”的非人性化文件夹。怎么样?

编辑:应该可能已经指定了--bare repo不是这里的克隆目标。

3 个答案:

答案 0 :(得分:5)

您不需要外部脚本来包装它!这正是git别名的用途,例如:我有一个名为clonez的别名。将以下内容添加到您的~/.gitconfig

[alias]
    clonez = "!sh -c 'git clone $1 ${1##*/}' -"

用法:

git clonez git://github.com/till/jsonlint.git

完成。创建本地文件夹jsonlint.git

答案 1 :(得分:1)

在执行路径中创建一个名为git-myclone的新脚本(或任何你想要的)。在其中,创建一个与URL的最后一个模式匹配的脚本,并根据URL的正则表达式匹配添加所需的存储库目录。 IE,接近(但我会让你为自己定制):

#!/bin/sh

url=$1
dir=$2

if [ "$2" = "" ] ; then
    dir=`echo "$url" | sed 's#.*/##'`.git
fi

git clone $url $dir

然后'git myclone URL'应该可以正常工作。

答案 2 :(得分:0)

git clone --mirror <url-path>
git clone --bare <url-path>

将保留或附加.git后缀,因为它是裸存储库的默认命名约定。