How do I set default aliases or other configuratio

2019-03-02 17:45发布

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.

I.e., I would like to do:

git clone <remote-repo>

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

[alias]
    st = status

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 config alias
2条回答
别忘想泡老子
2楼-- · 2019-03-02 18:06

I would discourage trying to impose your preferred interface with git on other users just because they clone a repo you set up. It may just be that you used an over-simplified example, but to be blunt it's none of your business whether a user sets st as an alias for status.

If you think there's some reason why working with your repo really calls for certain aliases, then you could include a script that sets them up in the root of your project. You could then document this in whatever ways you like - a README file, notes on your project page, etc.

But for the mere act of cloning to cause aliases to be set up - even local to that new clone - would be a massive security hole, so not only can't it be done, but I would expect this never to change.

查看更多
Evening l夕情丶
3楼-- · 2019-03-02 18:10

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.

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.

查看更多
登录 后发表回答