如何为git存储库设置默认别名或其他配置? [英] How do I set default aliases or other configuration for my git repository?

查看:139
本文介绍了如何为git存储库设置默认别名或其他配置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为git存储库设置一些默认别名和其他配置,以便在新用户对其进行克隆时,他们可以立即在该项目中使用这些别名。

I'd like to set some default aliases and other configuration for a git repository, so that when new users clone it they have those aliases immediately available for them in that project.

即,我想这样做:

git clone <remote-repo>

然后以 .git / config 其中具有一些预设别名,例如:

And then end up with a .git/config which has some preset aliases in it, such as:

[alias]
    st = status

我当时想我可以编辑 .git / config 远程存储库,但这不起作用。

I was thinking I could edit .git/config in the remote repository, but that doesn't work.

有什么办法可以实现这一目标?

Is there any way I can make this happen?

推荐答案

您不能直接这样做。一些配置(例如工具)非常依赖于平台(有时取决于用户),而git试图避免使用存储库的每个人都遇到麻烦。

You can not do that directly. Some of the configs, like the tools, are very platform dependent (sometimes user dependent), and git tries to avoid making that a problem for everyone using your repository.

例如,您当然不希望允许某人为整个存储库设置默认的非本地用户名和电子邮件,或者最终在Windows Checkout上使用一堆仅Linux的合并工具。

For example, you certainly would not want to allow someone to set a default non-local username and email for the whole repo, or to end up with a bunch of Linux-only merge tools on a Windows checkout.

也就是说,没有什么可以阻止您在项目的根目录中放入带有所需命令的脚本,并要求用户在首次克隆时运行该脚本。当您已经手动克隆项目时,这开销相对较小。例如,要设置别名,请在脚本中执行以下操作:

That being said, there is nothing stopping you from putting in a script with whatever commands you want in the root directory of your project and asking users to run it when they first clone. This is relatively little overhead when you are already cloning the project manually. For example, to set up your alias, do something like this in your script:

git config --local alias.st status

这还有一个额外的优势,那就是让您为不同的平台编写不同的脚本。

This has the additional advantage of letting you write different scripts for different platforms.

这篇关于如何为git存储库设置默认别名或其他配置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆