在 Git Config 中编辑远程引用

问题描述 投票:0回答:1

我与 Gerritt 合作,需要一些帮助来自动执行代码检查过程中的手动步骤。这是背景。当我重新克隆我的存储库时,这是我在 Git 配置(在 .git 文件夹内)中看到的内容。

[remote "origin"]
    url = https://[email protected]/contentpipeline.git
    fetch = +refs/heads/*:refs/remotes/origin/*

我们在 git 配置中手动进行以下更改。 (参考第二行)

[remote "origin"]
    push = +refs/heads/MYBRANCH:refs/for/MYBRANCH
    url = https://[email protected]/contentpipeline.git
    fetch = +refs/heads/*:refs/remotes/origin/*

添加带有推送的行,以便更改不会直接推送到 MYBRANCH,而是被视为“推送以供审核”。

我有两个问题:

  1. 可以使用 git CLI 命令自动执行此手动添加吗?
  2. 我们使用 NOde JS 框架 simple-git (https://www.npmjs.com/package/simple-git?activeTab=readme) 来自动化此过程。这也可以使用 simple-git 来完成吗?

非常感谢, 普拉巴尔

git gerrit simple-git
1个回答
0
投票

可以使用

git config [path.to.setting] [value]
添加 git config 中的任何设置。

您的情况:

git config remote.origin.push +refs/heads/MYBRANCH:refs/for/MYBRANCH

为了说明:

# after running:
git config foo.bar.baz Hello

# I get:
cat .git/config | tail -2
# [foo "bar"]
#   baz = Hello
© www.soinside.com 2019 - 2024. All rights reserved.