使用本地中央存储库和2台开发人员机器的开源贡献

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

我想为开源项目做贡献。我在两个不同的地方工作和生活。我有一个VPN设置,可以从两个位置访问本地中央存储库(在我的家庭网络中)。我有2台开发人员桌面计算机。

this similar question的不同之处在于我想使用一个服务器,我首先克隆源代码,然后在那里创建分支,并从那里将提交合并到Gitlab远程存储库。

让我们以Gitlab上的开源项目为例。我在我的中央服务器上做一个git clone https://gitlab.example.com/opensource.git然后在那里创建一个分支git checkout -b new_feature。然后我在桌面计算机上通过git clone central-server:/srv/data/Git/opensource将它克隆到两台桌面计算机上。我在我的一台开发者机器上开发并提交了更改。当我尝试推送更改时,我收到错误消息,请参阅下文。我也尝试了裸存储库,但也收到了错误消息。当我实现更改并进行测试时,我想将更改从中央服务器推送到Gitlab存储库。

问题:这里最好的工作流程和git命令是什么?

[user@laptop src]$ git branch
* new_feature
  master
[user@laptop src]$ git status
On branch new_feature
Your branch is ahead of 'origin/new_feature' by 2 commits.
  (use "git push" to publish your local commits)

nothing to commit, working tree clean
[user@laptop src]$ git push
Enumerating objects: 22, done.
Counting objects: 100% (22/22), done.
Delta compression using up to 4 threads.
Compressing objects: 100% (13/13), done.
Writing objects: 100% (13/13), 1.90 KiB | 1.90 MiB/s, done.
Total 13 (delta 11), reused 0 (delta 0)
remote: error: refusing to update checked out branch: refs/heads/new_feature
remote: error: By default, updating the current branch in a non-bare repository
remote: is denied, because it will make the index and work tree inconsistent
remote: with what you pushed, and will require 'git reset --hard' to match
remote: the work tree to HEAD.
remote: 
remote: You can set the 'receive.denyCurrentBranch' configuration variable
remote: to 'ignore' or 'warn' in the remote repository to allow pushing into
remote: its current branch; however, this is not recommended unless you
remote: arranged to update its work tree to match what you pushed in some
remote: other way.
remote: 
remote: To squelch this message and still keep the default behaviour, set
remote: 'receive.denyCurrentBranch' configuration variable to 'refuse'.
To central-server:/srv/data/Git/opensource
 ! [remote rejected] new_feature -> new_feature (branch is currently checked out)
error: failed to push some refs to 'central-server:/srv/data/Git/opensource'
[user@laptop src]$ 
git
1个回答
1
投票

您已将远程存储库初始化为标准库(带工作空间),并且您正在尝试推送它。

换句话说,central-server:/srv/data/Git/opensource里面有.git文件夹。您需要创建裸存储库:

central-server:/srv/data/Git$ git clone --bare ./opensource opensource_bare
laptop:~$ git clone central-server:/srv/data/Git/opensource_bare <somewhere>
laptop:~$ <work on your new clone here>
laptop:~$ git push 

由于评论不是一个给出答案的好地方,这就是我要做的。我们假设您有4台机器:

  • laptop1
  • laptop2
  • 中央服务器
  • gitlab服务器

laptop1和laptop2将拥有存储库的克隆,并配置了2个远程存储库(git remote add ...):

  • 中央服务器
  • gitlab服务器

无论什么时候你想推送“完成”的东西,你都会推送到gitlab-server。无论何时您想推进正在进行的工作,您都可以使用中央服务器。后者可用于同步laptop1和laptop2之间的工作。

合并总是在克隆上完成,因此仅适用于laptop1和laptop2。 central-server将仅用作可从laptop1和laptop2访问的其他远程存储库。

© www.soinside.com 2019 - 2024. All rights reserved.