在gitconfig中配置条件推送

  • 本文关键字:条件 配置 gitconfig git
  • 更新时间 :
  • 英文 :


到目前为止,我们团队中有两个存储库。一个是发展,另一个是生产。

因此,我们将gitconfig全局文件配置为默认的从Production获取,并默认推送到Development。

现在我们介绍了第三个名为Common的存储库。从"Common"克隆的任何人都应将默认推送配置为"Common)"。由于我们已将"Development"配置为全局中的默认推送存储库,因此在克隆"Common"存储库时,默认推送甚至指向"Development"。

如何在gitconfig global中制作以下内容?

if (cloned repository from Production)
then 
    default push is Development
if  (cloned repository from Common)
then 
    default push is Common

假设您的全局配置文件包含以下内容:

[remote "origin"]
pushurl = http://url/to/development

这里有一种方法可以实现你想要的:

  1. Common存储库中定义一个指向与origin:相同URL的新远程

    git remote add common http://url/to/common
    
  2. 本地配置文件中的remote.pushDefault变量设置为common:

    git config remote.pushDefault common 
    

remote.pushDefault设置告诉Git使用指定远程中定义的URL而不是origin进行推送。

以下是文档:

remote.pushDefault
默认情况下要推送的遥控器。覆盖所有分支的branch.<name>.remote,并由覆盖branch.<name>.pushRemote用于特定分支。

在这种情况下,origin的推送URL是在全局配置文件中定义的,但Common存储库将使用在其自己的远程(名为common)中定义的推送URL。

最新更新