开发者

git clone - how to keep .git in folder name by default

From ma开发者_如何学运维n 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.

I want to have my git-clone make apparently non-humanish folders named "project.git" by default. How?

edit: Should've probably specified, --bare repo is not the clone goal here.


You don't need external scripts to wrap this! This is exactly what git aliases are for, e.g. I have an alias called clonez. Add the following to your ~/.gitconfig:

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

Usage:

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

Done. Creates a local folder jsonlint.git.


Create a new script in your execution path called git-myclone (or whatever you want). In it, create a script that matches the last pattern of the URL and adds the required repository directory based on a regexp match of the URL. IE, something close to (but I'll let you tailor it for yourself):

#!/bin/sh

url=$1
dir=$2

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

git clone $url $dir

Then 'git myclone URL' should work as you want.


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

Will preserve or append the .git suffix, as it is the default naming convention for bare repositories.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜