Git - 如何 Push/Clone 在本地计算机上使用 2 个文件夹

Git - How to Push/Clone using 2 Folders on Local Machine

所以我才刚刚开始学习 Git 并且我正在尝试学习服务器和客户端之间的关系。我还不想开始使用 GitHub。最终的目标是将我的 NAS 用作服务器。我的策略是在我的本地计算机上创建两个文件夹:"RemoteTest" 和 "LocalTest" 文件夹,它们将充当我的客户端和服务器。

这是我所做的:

  1. 首先创建了 2 个文件夹:RemoteTest 和 LocalTest
  2. 在LocalTest中,执行git init
  3. 在RemoteTest中,执行git init --bare
  4. 在 LocalTest 中,创建了新文件 test.txt
  5. 使用 git add test.txt
  6. 在 LocalTest 中添加 "test.txt"
  7. 承诺使用 git commit -m "Testing 123"
  8. 使用 git remote add origin ~/Desktop/RemoteTest
  9. 添加了远程位置
  10. 尝试使用 git push
  11. 将内容推送到 RemoteTest

在第 8 步之前一切正常,然后出现 2 个错误:

  1. 致命:远端意外挂断
  2. 列表项错误:无法将某些引用推送到 'c:/Users/Test/Desktop/RemoteTest'

我做错了什么?使用最新版本的 Git 和 Windows 8.1。

谢谢

错误

git push github master
To git@github.com:Joey-project/project.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'git@github.com:Joey-project/project.git'

过去在这里讨论过!

想法是使用以下命令的变体:

git fetch github; git merge github/master

我建议你也看看 How do I push amended commit to the remote Git repository?,它有很多额外的信息..

如果您只是按照您概述的步骤进行操作,您的本地分支没有上游分支,因此 git push 将不知道要推送到哪里。

如果这是问题所在,只需执行 git push origin master(或者如果您希望您的分支记住它,则使用 --set-upstream)应该可以。

(免责声明,我希望错误消息是

fatal: The current branch master has no upstream branch.
To push the current branch and set the remote as upstream, use

    git push --set-upstream origin master

而不是你的错误。)

如果没有,请检查您是否正确添加了遥控器,从 检查 git remote -v 说的是什么。我不知道 Windows,但你的第二个错误表明遥控器确实设置正确。