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

时间:2018-09-10 05:43:55

标签: git

我想为开源项目做贡献。我在两个不同的地方工作和生活。我有一个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]$ 

1 个答案:

答案 0 :(得分: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。每当您希望进行工作时,都可以使用中央服务器。后者可用于在笔记本电脑1和笔记本电脑2之间同步您的工作。

合并总是在克隆上完成,因此仅在laptop1和laptop2上。中央服务器将仅用作可从laptop1和laptop2访问的附加远程存储库。

相关问题