如何在多个地方将git添加到现有项目 [英] How to add git to existing project in multiple places

查看:41
本文介绍了如何在多个地方将git添加到现有项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在本地有一个项目,服务器中也有相同的版本.现在,我将git添加到我的本地项目中,并提交了所有文件,并将代码推送到远程.

I have a project in my local and the same version is also in the server. Now I added git to my local project and committed all the files, and pushed the code to the remote.

如何将git添加到服务器中的项目中?本地提交(或远程提交)也应该在项目的服务器版本中可用.

How can I add git to the project, which is in the server? The local commits (or remote commits) should also be available in the server version of the project.

推荐答案

在服务器上,您需要创建两个新的存储库-一个在工作树中,另一个在其他地方;第二个必须是裸存储库(仅.git,缺少工作树),因为大多数情况下允许将推送推送到裸存储库; git面向基于拉的工作流.有很多方法可以推销到裸机仓库,但我建议避免这种情况.

At the server you need to create two new repositories — one in the working tree and one somewhere else; the second one must be bare repository (only .git, lacking a worktree) because pushing is mostly allowed to bare repositories; git oriented towards pull-based workflows. There are ways to push to non-bare reposirtories but I recommend to avoid that.

将裸存储库作为远程origin添加到本地存储库并进行推送.然后在服务器上,将裸仓库从裸仓库拉到非裸仓库.

Add the bare repository as the remote origin to your local repository and push. Then at the server pull from the bare repository to non-bare.

类似的东西:

# create repositories at the server
ssh user@server "
cd /path/to/non-bare &&
git init &&
cd /path/to/bare.git &&
git init --bare
" &&

# add remote and push
git remote add origin user@server:/path/to/bare.git &&
git push origin master &&

# at the server pull from bare to non-bare
ssh user@server "
cd /path/to/non-bare &&
git pull /path/to/bare.git master
"

最后一个可以使用服务器端挂钩实现自动化但是您最好手动进行操作以学习然后自动化.

The last one could be automated using a server-side hook but you better do things manually to learn and then automate.

这篇关于如何在多个地方将git添加到现有项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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