与Git的混淆

与Git的混淆,git,Git,我是Git新手,有点困惑(今天才开始使用它)。我有以下问题。在工作中,我有git repo,我把它克隆到我的笔记本电脑上。在家里,我从笔记本电脑克隆到台式电脑 工作服务器->git克隆->笔记本电脑->git克隆->台式电脑 所以在我对源代码做了一些更改之后,我键入以下命令“gitpush”。据我所知,我只是推动对本地回购协议的修改。然后我尝试“推送orgin master”,我得到以下错误: Counting objects: 3, done. Delta compression using

我是Git新手,有点困惑(今天才开始使用它)。我有以下问题。在工作中,我有git repo,我把它克隆到我的笔记本电脑上。在家里,我从笔记本电脑克隆到台式电脑

工作服务器->git克隆->笔记本电脑->git克隆->台式电脑

所以在我对源代码做了一些更改之后,我键入以下命令“gitpush”。据我所知,我只是推动对本地回购协议的修改。然后我尝试“推送orgin master”,我得到以下错误:

Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 289 bytes, done.
Total 2 (delta 1), reused 0 (delta 0)
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_name@host:~/path/to/folder/.git
 ! [remote rejected] master -> master (branch is currently checked out)
error: failed to push some refs to 'user_name@host:~/path/to/folder/.git'

在我的笔记本电脑里,我没有看到任何变化。那么在这种情况下我该怎么办?什么是正确的方法?你能详细解释一下吗?提前感谢您的回答

阅读错误,它用简单的英语给出了清晰的说明

Git不会将工作目录签出到您试图覆盖的分支的repo推送到,因为(可能)这是其他人的工作目录,而且他们可能不希望您在处理repo时更改他们的repo

这样想:当您使用Git时,您基本上是在准备一个补丁来应用于当前签出的分支,以便将它从一个状态
a
,移动到另一个状态
B
。为此,您可以对工作目录进行更改,并使用
git add
暂存它们,然后使用
git commit
提交它们以生成
B
。如果有人推送到您的存储库并修改您所在的分支,状态
A
将不断变化,您的工作将不断失效。您实际上是在尝试生成一个应用于移动目标的补丁。默认情况下,Git拒绝让您陷入这种情况

您需要将笔记本电脑的回购协议设置为“裸”回购协议,或者在按下之前查看笔记本电脑上的其他分支,或者按照说明,将
receive.denycurrentbrack
设置为忽略或警告


避免这种情况的最佳方法是,从笔记本电脑将更改从桌面拖到笔记本电脑,而不是从桌面推送。是否将更改推送到正确的服务器(而不是笔记本电脑)?在尝试推送之前是否再次从远程推送?“克隆”会将桌面上的源设置为笔记本电脑。您可能需要调整.git/config中的设置,以将原点更改为指向工作服务器。我想将更改推送到笔记本电脑。在我的工作中不适合服务器。因为我不能从家里访问我的服务器,所以它在防火墙后面。当我试图从我的笔记本电脑上拔出时,我收到一条消息“已经是最新的”消息要从桌面拔出到笔记本电脑上,你必须将其作为笔记本电脑上的另一个遥控器添加。这里记录了遥控器:非常感谢您的帮助。我成功地将更改从桌面转移到笔记本电脑。我刚刚在我的笔记本电脑上添加了另一个远程分支。和“git拉桌面主机”。像我一样工作。如何训练自己使用git?你能给我推荐一些好的教程吗?或者某种实践方法?实际上,避免这种情况的更好方法是拥有一个单独的裸存储库(即使它只是台式机或笔记本电脑上的一个单独的共享目录),两者都可以推送和拉出。这样就不必担心覆盖工作目录了,不过还需要一个额外的步骤。@Kyralessa Git设计用于在对等点之间进行拉取;这就是它最好的工作方式。没有必要进行第三次裸回购。@meagar,[需要引证]。