【问题标题】:How can I share working repository with another user (push/pull)?如何与其他用户共享工作存储库(推/拉)?
【发布时间】:2015-04-26 23:46:42
【问题描述】:

我通过运行从 Assembla 克隆了一个 Git 存储库:

git clone git@git.assembla.com:[my_project].git

如何与其他用户共享我的工作存储库(位于/usr/local/project),以便他们可以直接从我的工作存储库中获取/拉取和推送到我的工作存储库?

我已经尝试通过运行从我的工作存储库初始化 Git 存储库:

git init

git init --bare

然后我使用另一台计算机将提交推送到我的工作存储库,但我收到错误:

Pushing to /usr/local/project/
remote: error: refusing to update checked out branch: refs/heads/master[K
remote: error: By default, updating the current branch in a non-bare repository[K
remote: error: is denied, because it will make the index and work tree inconsistent[K
remote: error: with what you pushed, and will require 'git reset --hard' to match[K
remote: error: the work tree to HEAD.[K
remote: error: [K
remote: error: You can set 'receive.denyCurrentBranch' configuration variable to[K
remote: error: 'ignore' or 'warn' in the remote repository to allow pushing into[K
remote: error: its current branch; however, this is not recommended unless you[K
remote: error: arranged to update its work tree to match what you pushed in some[K
remote: error: other way.[K
remote: error: [K
remote: error: To squelch this message and still keep the default behaviour, set[K
remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.[K
To /usr/local/project/
 ! [remote rejected] master -> master (branch is currently checked out)
error: failed to push some refs to '/usr/local/project'

【问题讨论】:

    标签: git git-clone git-init


    【解决方案1】:

    这似乎与我曾经遇到的一个问题非常相关:

    error: refusing to update checked out branch: refs/heads/master
    

    我听说这是因为分支处于非裸状态。如果有人向这个分支推送,它将覆盖已签出副本的现有状态。

    一般的解决方案是使用裸存储库,通过以下方式完成:

    git init --bare
    

    另一种可能是使用分支

    git push fails: `refusing to update checked out branch: refs/heads/master` 还给了我一些关于如何解决它的深刻见解!

    祝你好运! :)

    乔伊

    【讨论】:

    • 感谢您的评论,它确实帮助我解决了问题。我无法推送到本地工作存储库的原因是我仍在“主”分支上工作,因此其他人无法推送到它。为了解决这个问题,我只是切换到其他分支或像 mathewballard 所说的那样设置一个远程仓库
    【解决方案2】:

    如果您要在多台计算机之间进行协作甚至共享,则必须设置远程存储库。通常人们使用诸如 Github 或 Unfuddle 之类的服务来托管远程仓库。但是,您也可以设置自己的。官方 Git documentation 会帮助你。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-02-10
      • 1970-01-01
      • 2019-04-12
      • 1970-01-01
      • 1970-01-01
      • 2013-08-25
      • 1970-01-01
      • 2018-07-13
      相关资源
      最近更新 更多