将Git Repo推送到远程服务器 [英] Pushing Git Repo to Remote Server
问题描述
我在我的vps上设置了一个--bare repo,在我的本地主机上设置了一个repo 。
我已经使用以下命令推送到VPS:
#git remote add origin ssh://root@mysite.net/home/mysite/public_html/mygit/.git
#git push origin master
成功推送,但我需要做的是检出VPS .git中的文件。但是,当我尝试运行'git checkout'时,我得到错误:
$ b
致命:这个操作必须在工作树中运行
p>
我试过编辑.git配置文件并编辑/添加这些行:
[core]
bare = true
worktree = / home / mysite / public_html / mygit /
[receive]
denycurrentbranch = false
这允许我运行git命令,但是这些文件不会签出,而git会告诉我的文件已被删除。
我只是有点困惑。我应该如何解决这个问题?解决方案
尝试在裸仓库上执行签出是非常不合逻辑的 - checkout
是更新工作副本/树的命令:
git-checkout - 签出分支或到工作树的路径
裸仓库没有工作树。
以正常的方式设置你的git仓库
因此,从零开始,我们假设你在你的家庭/办公室计算机上:
创建裸回购
为您的项目创建裸回购 - 或将现有回购移至适当的位置:
ssh root@mysite.net
cd回购
mkdir repo.git ##给它一个更好的名字
cd repo.git
git init --bare
为您的网站制作一个复本
ssh root@mysite.net
cd / home / mysite / public_ html
git clone〜/ repos / repo.git。
创建本地克隆
cd mylocalsite / public_html
git clone root@mysite.net:repos / repo.git。
git push / pull等
自动更新网站
由于您的目标是自动更新,您可以使用git-hooks来更新工作副本,这是您的实时站点,只要您推送到您的仓库。
以下是一个简单的例子:
#!/ bin / sh
cd / home / mysite / public_html
git --git-dir /home/mysite/public_html/.git pull> / dev / null
将其另存为 / home / root / repos /。 git / hooks / post-receive
,使其可执行,并且每次推送时,它都会尝试更新您的现场网站,方法是发出一个拉
或
您可以放弃使用裸存储库,并将您的现场网站的结帐作为主/唯一存储库。这是不推荐,但如果您选择这样做,您可以这样做:
git remote add live root@mysite.net:/home/mysite/public_html/.git
git push live master
它会给你一个关于更新当前签出分支的错误,阅读警告并理解它的含义。如果您决定仍然希望这样做,您可以允许它使用:
ssh root@mysite.net
cd / home / mysite / public_html
git config receive.denyCurrentBranch忽略
再次不推荐,最好有一个裸回购和维护您的现场作为一个正常结帐。
So I am trying to push a repo from my localhost to my VPS.
I have setup a --bare repo on my vps and a repo on my localhost.
I have used the following commands to push to the VPS:
# git remote add origin ssh://root@mysite.net/home/mysite/public_html/mygit/.git
# git push origin master
It pushes successfully, but what I need to be able to do is checkout the files from the VPS .git. But, when I try running 'git checkout' I get the error:
fatal: This operation must be run in a work tree
I have tried editing the .git config file and editing/adding these lines:
[core]
bare = true
worktree = /home/mysite/public_html/mygit/
[receive]
denycurrentbranch = false
This allows me to run git commands, but the files wont checkout, and git tells me files have been deleted.
I am just a little bit confused. How should I be going about this?
Trying to perform checkouts on a bare repository is quite illogical - checkout
is a command for updating your working copy/tree:
git-checkout - Checkout a branch or paths to the working tree
A bare repository doesn't have a working tree.
Setting up your git repos the normal way
So starting from zero, let's assume you are on your home/office computer:
Create bare repo
Create a bare repo for your project - or move your existing repo to some appropriate location:
ssh root@mysite.net
cd repos
mkdir repo.git ##give it a better name
cd repo.git
git init --bare
Make a clone for your site
ssh root@mysite.net
cd /home/mysite/public_html
git clone ~/repos/repo.git .
Create a local clone
cd mylocalsite/public_html
git clone root@mysite.net:repos/repo.git .
git push/pull etc.
Update site automatically
Since your goal is to update automatically, You can use git-hooks to update the working copy that is your live site whenever you push to your repo.
Here's a simple example:
#!/bin/sh
cd /home/mysite/public_html
git --git-dir /home/mysite/public_html/.git pull > /dev/null
save it as /home/root/repos/.git/hooks/post-receive
, make it executable, and every time you push, it'll attempt to update your live site by issuing a pull
OR
you can forgoe the use of a bare repository and use your live site's checkout as your main/only repository. This is not recommended but if you choose to do so, you would do:
git remote add live root@mysite.net:/home/mysite/public_html/.git
git push live master
It'll give you an error about updating the currently checked-out branch, read the warning and understand what it means. If you decide you still want to do this you can allow it to work with:
ssh root@mysite.net
cd /home/mysite/public_html
git config receive.denyCurrentBranch ignore
Again not recommended, much better to have a bare repo and maintain your live site as a normal checkout.
这篇关于将Git Repo推送到远程服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!