昨天,我发布了一个有关如何将Git存储库从个人一台计算机克隆到另外一台计算机的问题 , 如何从另外一台计算机“ git clone”? 。 git
如今,我能够成功地将Git存储库从源(192.168.1.2)克隆到目标(192.168.1.1)了。 web
可是,当我对文件, 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)。 那多是缘由吗? less
使用Git同步Android手机和笔记本电脑上的存储库时,我遇到了一样的问题。 对我来讲,解决方案是执行拉动,而不是像@CharlesBailey建议的那样进行推进。 ssh
Android存储库上的git push origin master
对于我失败,并显示与@ hap497相同的错误消息,这是因为推送到存储库+工做副本的裸机检出。 post
笔记本电脑存储库上的git pull droid master
和work-copy对我有用。 固然,您以前须要运行git remote add droid /media/KINGSTON4GB/notes_repo/
。 测试
您能够经过如下测试来查看bare
服务器的工做方式: 网站
想象一下,您有一个工做站和一个托管有实时站点的服务器,而且您想不时更新此站点(这也适用于两个开发人员经过一个裸露的中间人来回发送其工做的状况)。 ui
在本地计算机上建立一些目录并cd
进入该目录,而后执行如下命令: this
# initialization git init --bare server/.git git clone server content git clone server local
server
目录(请注意最后的.git)。 该目录仅用做存储库文件的容器。 content
目录。 这是您的现场/生产目录,将由您的服务器软件提供服务。 如今这是基本的工做流程:
输入local
目录,建立一些文件并提交。 最后将它们推送到服务器:
# create crazy stuff git commit -av git push origin master
如今进入content
目录并更新服务器的内容:
git pull
重复1-2。 这里的content
多是另外一个也能够推送到服务器的开发人员,也多是local
开发人员,您能够从他那里获取。
最好的方法是:
mkdir ..../remote cd ..../remote git clone --bare .../currentrepo/
这将克隆存储库,但不会在.../remote
建立任何工做副本。 若是查看远程目录,将会看到一个建立的目录,名为currentrepo.git
,这多是您想要的。
而后从您本地的Git存储库中:
git remote add remoterepo ..../remote/currentrepo.git
进行更改后,您能够:
git push remoterepo master
我不得不在现有的裸仓库中从新运行git --init
,这已经在裸仓库树中建立了一个.git
目录-我意识到在那里输入git status
后。 我删除了,一切都很好:)
(全部这些答案都是不错的,但就我而言,这是彻底不一样的(据我所知),如前所述。)
经过一些设置步骤,您可使用单线轻松将更改部署到您的网站
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/ 。 在此处查找有关发生的状况的更详细说明。