git 提交到克隆的存储库

标签 git

在下面的代码中我需要一些有关克隆的信息

有一个由命令创建的主存储库

              mkdir git_repo
              cd git_repo
              git init --bare //creates empty repo

然后用户将克隆 git_repo

              git clone git_repo user_repo

用户将再次克隆新的以创建备份

             git clone user_repo user_bk
             cd user_bk
             //user will edit an existing file and commit it
             git push origin master
            Counting objects: 5, done.
            Delta compression using up to 8 threads.
            Compressing objects: 100% (2/2), done.
            Writing objects: 100% (3/3), 294 bytes, done.
            Total 3 (delta 0), reused 0 (delta 0)
            Unpacking objects: 100% (3/3), done.
            remote: error: refusing to update checked out branch: refs/heads/master
            remote: error: By default, updating the current branch in a non-bare repository
            remote: error: is denied, because it will make the index and work tree inconsistent
            remote: error: with what you pushed, and will require 'git reset --hard' to match
            remote: error: the work tree to HEAD.
            remote: error:
            remote: error: You can set 'receive.denyCurrentBranch' configuration variable to
            remote: error: 'ignore' or 'warn' in the remote repository to allow pushing into
            remote: error: its current branch; however, this is not recommended unless you
            remote: error: arranged to update its work tree to match what you pushed in some
            remote: error: other way.
            remote: error:
            remote: error: To squelch this message and still keep the default behaviour, set
            remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.
            To user_repo
             ! [remote rejected] master -> master (branch is currently checked out)
            error: failed to push some refs to 'user_bk'newtest by user

我的问题是

1.在 git 中我们可以 checkin 克隆的存储库

2.如果必须这样做,那么该怎么做

3.如何解决上述错误情况

最佳答案

转到 user_repo,然后:

git config --local --add receive.denyCurrentBranch ignore

然后你就可以做你尝试过的事情了。 但是,正如打印输出中所述,不建议这样做。为什么要在备份中提交内容?使用 git clone --bare 来创建备份。

关于git 提交到克隆的存储库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9227744/

相关文章:

git - 有没有办法删除所有先前提交的 gpg 标志或使用另一个 gpg key 重新签名

python - 将 PyCharm 与 Git 一起使用时,我应该忽略 .idea 文件夹吗?

git - 将 stash 应用到不同的分支

linux - Jenkins 无法运行 Maven

git - 将多个 .gitignore 文件(本地和远程)保存在同一个存储库中

git - 修复 git 中的两个 bug 的正常流程是什么?

git - JetBrains : Show local changes made in this branch

git - 如何解决 Git 存储库中的 merge 冲突?

git - 你有 xxx 和 xxx/yyy.zz 错误 : Error building trees

ruby-on-rails - Capistrano问题