代码之家  ›  专栏  ›  技术社区  ›  Wirawan Purwanto danodonovan

Git远程和推送参考规范

git
  •  2
  • Wirawan Purwanto danodonovan  · 技术社区  · 7 年前

    Git提供了“Git remote add”子命令来创建一个新的remote,在配置文件中,有一个“fetch=”参数。在这种情况下,我在两台或多台计算机上处理相同的git repo,并且我希望能够将更改从一台计算机传输到另一台计算机。等等 machine1 ,我会设置一个遥控器 machine2

    $ git remote add machine2 ssh://user@machine2/home/user/codes/mywork
    

    这是远程创建后的状态:

    $ git remote -v
    machine2    ssh://user@machine2/home/user/codes/mywork (fetch)
    machine2    ssh://user@machine2/home/user/codes/mywork (push)
    

    以及 .git/config 对于该回购:

    [remote "machine2"]
        url = ssh://user@machine2/home/user/codes/mywork
        fetch = +refs/heads/*:refs/remotes/machine2/*
    

    .git/配置 作为 git remote add

        push = +refs/heads/*:refs/remotes/machine1/*
    

    所以 git push 从我当前的机器( )会把所有的修改都放在一个名为“的远程分支上” 机器1 机器2 的回购。

    问题是: 有没有一种方法可以自动创建这个push refspec或使用命令行而不必编辑 .git/配置 手动?我想知道我上面使用的Git工作流是否不再那么常见,因为github或gitlab真的成为人们跨机器进行开发的方式。

    0 回复  |  直到 7 年前