昨天,我发布了一个关于如何从我的一台机器克隆Git存储库到另一台机器的问题,我如何从另一台机器“克隆Git”?

现在我可以成功地将Git存储库从源存储库(192.168.1.2)克隆到目标存储库(192.168.1.1)。

但是当我对文件进行编辑,git commit -a -m "test"和git push时,我在目的地(192.168.1.1)上得到了这个错误:

git push                                                
hap@192.168.1.2's password: 
Counting objects: 21, done.
Compressing objects: 100% (11/11), done.
Writing objects: 100% (11/11), 1010 bytes, done.
Total 11 (delta 9), reused 0 (delta 0)
error: refusing to update checked out branch: refs/heads/master
error: By default, updating the current branch in a non-bare repository
error: is denied, because it will make the index and work tree inconsistent
error: with what you pushed, and will require 'git reset --hard' to match
error: the work tree to HEAD.
error: 
error: You can set 'receive.denyCurrentBranch' configuration variable to
error: 'ignore' or 'warn' in the remote repository to allow pushing into
error: its current branch; however, this is not recommended unless you
error: arranged to update its work tree to match what you pushed in some
error: other way.
error: 
error: To squelch this message and still keep the default behaviour, set
error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.
To git+ssh://hap@192.168.1.2/media/LINUXDATA/working
! [remote rejected] master -> master (branch is currently checked out)
error: failed to push some refs to 'git+ssh://hap@192.168.1.2/media/LINUXDATA/working'

我正在使用两个不同版本的Git(远程上的1.7版本和本地机器上的1.5版本)。这是一个可能的原因吗?


当前回答

我的解决方案(正在使用中)

在远程服务器上签出“master” 在“开发”部门工作 将更改推送到远程开发人员 在远程上将开发人员合并为主机

宾戈游戏

其他回答

我不得不在一个现有的裸库中重新运行git——init,这已经在裸库树中创建了一个.git目录-我意识到在那里输入git状态后。我把它删除了,一切又恢复正常了:)

(所有这些答案都很棒,但就我而言,我的情况完全不同(据我所知)。)

以防有人觉得有用。对我来说,这是一个git服务器权限问题。我检查了项目从乞求和推送一个简单的文件,然后我得到“推送拒绝:推送到原点/主被拒绝”

好的,如果您想要一个普通的远程存储库,那么创建一个额外的分支并签出它。将其推入一个分支(未签出),并在从本地推入后将其与当前活动的一个分支合并。

例如,在远程服务器上:

git branch dev
git checkout dev

在本地设置中:

git push 

远程服务器:

git merge dev

只需几个设置步骤,您就可以轻松地使用一行程序部署更改到您的网站

git push production

这很简单,你不需要登录到远程服务器并进行拉取或其他操作。请注意,如果您不将生产检出用作工作分支,这将是最好的工作方式!(OP的工作环境略有不同,我认为@Robert Gould的解决方案很好地解决了这个问题。此解决方案更适合部署到远程服务器。)

首先,你需要在你的服务器上的某个地方建立一个裸库,在你的webroot之外。

mkdir mywebsite.git
cd mywebsite.git
git init --bare

然后创建文件hooks/post-receive:

#!/bin/sh
GIT_WORK_TREE=/path/to/webroot/of/mywebsite git checkout -f

并使文件可执行:

chmod +x hooks/post-receive

在本地机器上,

git remote add production git@myserver.com:mywebsite.git
git push production +master:refs/heads/master

都准备好了!现在,将来您可以使用git push production来部署您的更改!

这个解决方案的功劳归http://sebduggan.com/blog/deploy-your-website-changes-using-git/。在那里可以找到关于正在发生的事情的更详细的解释。

例如,一旦创建了空(裸)存储库,就需要更改远程服务器上的配置文件

root@development:/home/git/repository/my-project# cat config 

你会看到

[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true

你将使这裸露为假为真,我删除了logallrefupdates = true(不确定它的使用!)

to

[core]
repositoryformatversion = 0
filemode = true
bare = true

您可以测试以下内容

$ git remote show origin
* remote origin
Fetch URL: my-portal@development:/home/XYZ/repository/XYZ
Push  URL: my-portal@development:/home/XYZ/repository/XYZ
HEAD branch: (unknown)

这个HEAD分支:(未知)将显示如果你不能PUSH。因此,如果HEAD分支是未知的,你应该将bare更改为true,在推送成功后,你可以重用

git remote show origin

你们会看到

 HEAD branch: master