将本地git仓库连接到谷歌云虚拟机 [英] Connect a local git repo to google cloud VM

查看:235
本文介绍了将本地git仓库连接到谷歌云虚拟机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试将本地python flask回购站连接到我在Google云中的远程(生产)虚拟机。

在Google VM上:

  sudo mkdir / home / git&& cd / home / git 
sudo mkdir flask_project.git&& cd flask_project.git
sudo git init --bare
$ b $ sudo vim hooks / post-receive
{added}
#!/ bin / sh
GIT_WORK_TREE = / home / www / flask_project git checkout -f

sudo chmod + x hooks / post-receive

On本地开发

  git init 
git remote添加制作网页@< externalip> ;:/ home / git / flask_project.git

我已经生成SSH密钥并将公钥添加到GCP元数据,但是当我将提交从本地推送到远程时:

  git push production master 

Git拖延并且提交没有到达远程。



任何想法我都可以链接回购?

解决方案

您的 /home/git/flask_project.git 裸仓库在您执行的步骤后由 root 拥有。



但您试图将其作为 web (根据您的远程生产n配置),它没有写裸露回购的权限。我怀疑取决于操作系统,这可能会导致挂起 - 在我以前的opensuse上,它只是失败:


remote:error:权限不足用于向存储库数据库对象添加对象

尝试 sudo chown -R web / home / git / flask_project。 git



或者,如果您计划以多个用户推送到该回购( git 想到),你可以使用 git init --bare --shared 来创建裸回购。注意:您还需要克服 / home / www / flask_project $ b

c>(如 web ),否则你可能会得到类似的结果:



< blockquote>

remote:fatal:此操作必须在工作树中运行



I've been trying to link a local python flask repo to my remote (production) vm in the google cloud.

On Google VM :

sudo mkdir /home/git && cd /home/git
sudo mkdir flask_project.git && cd flask_project.git
sudo git init --bare

sudo vim hooks/post-receive
{Added}
#!/bin/sh
GIT_WORK_TREE=/home/www/flask_project git checkout -f

sudo chmod +x hooks/post-receive

On Local dev

git init
git remote add production web@<externalip>:/home/git/flask_project.git

I've generated SSH keys and added public key to GCP Metadata but when I push commits from local to remote :

git push production master

Git stalls and the commit doesn't reach remote.

Any ideas how I can link the repo's?

解决方案

Your /home/git/flask_project.git bare repo is owned by root after the steps you executed.

But you're attempting to operate it as web (according to your remote production config), which doesn't have write permissions on the bare repo. I suspect that depending on the OS this may cause the hanging - on my older opensuse it just fails with:

remote: error: insufficient permission for adding an object to repository database objects

Try sudo chown -R web /home/git/flask_project.git

Alternatively, if you plan to push to that repo as multiple users (git comes to mind), you could use the git init --bare --shared to create the bare repo instead. Not a great practice, tho.

Side note: you also need to clone the repo in /home/www/flask_project (as web as well) before the hook can operate properly, otherwise you'll probably get something like:

remote: fatal: This operation must be run in a work tree

这篇关于将本地git仓库连接到谷歌云虚拟机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆