如何推送到非裸 Git 存储库? [英] How to push to a non-bare Git repository?

查看:40
本文介绍了如何推送到非裸 Git 存储库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通常通过 ssh(屏幕和 vim)在远程服务器上工作,在那里我有一个 Git 存储库.有时我不在线,所以我的笔记本电脑上有一个单独的存储库(从我的远程克隆).

I usually work on a remote server via ssh (screen and vim), where I have a Git repository. Sometimes I'm not online, so I have a separate repository (cloned from my remote) on my laptop.

但是,我无法从远程端的这个存储库中拉取数据,因为我通常在防火墙后面或者我没有公共 IP.

However, I can't pull from this repository on remote side because I'm usually behind a firewall or I don't have a public IP.

我读过我应该推送到一个裸仓库.然后我应该如何将更改推送到我的远程存储库?

I've read that I should push just to a bare repository. How should I then push my changes to my remote repository?

推荐答案

receive.denyCurrentBranch updateInstead

此选项已添加在 Git 2.3 中,它使服务器更新其工作树如果干净.

This options was added in Git 2.3, and it makes the server update its working tree if it is clean.

因此,如果您确保在本地拉取之前始终提交,并在服务器上保持一个干净的工作树(您应该这样做以避免合并冲突),那么此选项是一个很好的解决方案.

So if you ensure that you always commit before you pull locally, and keep a clean working tree on the server (which you should do to avoid having merge conflicts), then this option is a good solution.

示例用法:

git init server
cd server
touch a
git add .
git commit -m 0
git config --local receive.denyCurrentBranch updateInstead

cd ..
git clone server local
cd local
touch b
git add .
git commit -m 1
git push origin master:master

cd ../server
ls

输出:

a
b

这篇关于如何推送到非裸 Git 存储库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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