Git 使用别名简化克隆

Git 使用别名简化克隆,git,Git,我想创建一个类似以下内容的别名: alias getres="git clone https://github.com/user/" 目标是我可以键入“getres repository name”并获取存储库的名称 但是现在呢, 键入“getres存储库名称” 告诉我找不到repository时出错。发生这种情况是因为getres repository name被转换为: git clone https://github.com/user/ repository name 这意味着http

我想创建一个类似以下内容的别名:

alias getres="git clone https://github.com/user/"
目标是我可以键入“getres repository name”并获取存储库的名称

但是现在呢,

键入“getres存储库名称”


告诉我找不到repository时出错。

发生这种情况是因为
getres repository name
被转换为:

git clone https://github.com/user/ repository name
这意味着
https://github.com/user/
存储库名称
,这会完全弄乱您的URL

问题的解决方案是创建一个接受1个参数(存储库名称)的bash脚本,然后在别名中使用该脚本


请参见

您所追求的只是别名所无法达到的程度,而别名仅适用于最简单的情况。您需要一个shell函数,用于此,
getres(){git clonehttps://github.com/user/$*;}

我刚刚遇到了同样的问题

适用于使用zsh/oh my zsh/iterm2(1,2,3)的用户

我用以下内容更新了我的.zshrc文件:

function getrep(){
    git clone https://github.com/USERNAME/$1.git
}
我在末尾加了“.git”,因为我很懒

用例只是从终端“getrep REPNAME”克隆到您正在使用的任何当前文件夹中

(一)

(二)


(3)

git clone
命令前面添加
echo
,以便它输出想要执行的命令,而不是执行它,然后调整它,直到它生成正确的命令。很有可能没有使用参数。您需要一个shell函数来实现此,
getres(){git clonehttps://github.com/user/$*;}
您可以通过使用shell函数而不是别名来解决这个问题。是的,我是在写这个问题(同时也引用了另一个答案)我猜是在您写评论的时候