gpt4 book ai didi

git - 允许从本地推送到远程的简单 git 配置?

转载 作者:太空狗 更新时间:2023-10-29 14:40:20 24 4
gpt4 key购买 nike

我有两台机器:远程本地。我希望远程 成为我可以从本地 推送到的主要存储库。

我有一个当前的项目,它位于远程,我想将其存储到 git 的存储库中。

回答

由于文件最初位于远程,而且我还需要一个可以推送到远程 的裸存储库,这有点棘手。该过程本质上是一个 Bootstrap ,直到我启动了裸目录。

我用来设置和测试的顺序,正如 Paolo Capriotti 在下面的简短回答中所建议的那样:

  1. 远程上,在/home/me/depot/project上创建一个裸仓库
  2. 远程上,也创建一个工作的.git repo
  3. 本地,从远程上的工作仓库克隆
  4. local 上,编辑 .git/config 以便 [remote "origin"] 的 url 指向 remote
  5. 上的裸仓库
  6. 本地,编辑一些文件,提交到工作仓库
  7. 本地上,git push origin master 发布到远程上的裸仓库
  8. 远程上,编辑 .git/config 以指向远程上的裸仓库
  9. 远程上,git pull 从裸仓库中 pull

一个更简单的序列将涉及完全忽略本地目录。首先在远程 上设置工作和裸仓库,然后最后在本地 上,从远程 上的裸仓库克隆。

原始问题

我尝试了以下方法:

  1. 远程> git init && git add 。 && git commit -m "初始提交"
  2. local> git clone ssh://remote/path_to_remote_git
  3. 在本地编辑一个文件
  4. 本地> git commit -a
  5. 本地> pull
  6. local> git push origin master

失败

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.

所以我重新开始:在远程上 rm -rf .git 目录,在本地上 rm -rf。

我尝试在远程创建一个裸目录:

  1. 远程> export GIT_DIR=/home/me/depot/project.git
  2. 远程> git init && git add .

失败

fatal: This operation must be run in a work tree

项目开始但没有存储库,我必须经过哪些步骤才能从本地机器推送到远程机器?

如果可能的话,我更喜欢将 depot 放在远程的 /home/me/depot 目录中。

这是否意味着我需要远程上的裸仓库和非裸仓库?

最佳答案

使用 git init --bare 在远程创建一个裸仓库,不要添加任何文件。在本地创建一个存储库,添加您的文件,然后推送到远程。

关于git - 允许从本地推送到远程的简单 git 配置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8692518/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com