从多个拉,只推一个 [英] Pull from multiple, only push to one
问题描述
以下是我要瞄准的工作流程:
我有两个存储库。一个用PHP编写的网站框架,另一个用于自定义PHP代码,用于添加客户需要的网站功能。
我需要能够从两个存储库对于客户端网站,但只推送到一个,这将是自定义代码,我只想要第二个存储库来保存自定义代码,而不是框架。
我可以做到这一点吗?
我已经添加了两个存储库,但它总是进行合并(因为我使用 git pull
)但是如果我只用 git remote update
我的文件没有改变。
设置步骤:
远程:
mkdir〜/ git / framework.git
cd〜/ git / framework.git
git init --bare
mkdir〜/ git / client1.git
cd〜/ git / client1.git
git init --bare
本地:
mkdir〜/ www / framework
cd〜/ www / framework
git init
git remote add framework ss h://user@host/~/git/framework.git
mkdir〜/ www / client1
cd〜/ www / client1
git init
git远程添加框架ssh://user@host/~/git/framework.git
git remote add client ssh://user@host/~/git/client1.git
这是我的本地客户端配置:
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
precomposeunicode = true
[remoteframework]
url = ssh://user@host/~/git/framework.git
fetch = + refs / heads / *:refs / remotes / framework / *
[remoteclient]
url = ssh://user@host/~/git/client1.git
fetch = + refs / heads / *:refs / remotes / client / *
对于您的模式,您可以声明其中一个存储库只读只有根据这个答案(几个建议) 。然后你可以使用 git pull client
和 git pull framework
来同步,并且 git push客户端
来推送您的代码。要将 client
设置为默认远程,您可以执行 git branch --set-upstream-to client / master
(或者用默认的任何远程分支替换master)。
更常见的模式是使用分支来保持框架和客户端的分离。这也意味着您只需要两个存储库:您的共享裸存储库和您的本地开发存储库。你可以从 origin
,它有两个主要的分支, framework
和 client
。你可以选择从框架
到客户端
进行合并,你几乎不会从<$ c合并$ c>客户回到框架
。
Here is the workflow I am aiming for:
I have two repositories. One for the website framework coded in PHP, and the other is for custom PHP code for added website features the client wants.
I need to be able to pull from both repositories for the client website but only push to one, which would be the custom code, and I only want that second repository to hold the custom code, not the framework.
How can I achieve this?
I have both repositories added but it always does a merge (because I use git pull
) but if I use just git remote update
my files are not changed.
Steps I took for the setup:
Remote:
mkdir ~/git/framework.git
cd ~/git/framework.git
git init --bare
mkdir ~/git/client1.git
cd ~/git/client1.git
git init --bare
Local:
mkdir ~/www/framework
cd ~/www/framework
git init
git remote add framework ssh://user@host/~/git/framework.git
mkdir ~/www/client1
cd ~/www/client1
git init
git remote add framework ssh://user@host/~/git/framework.git
git remote add client ssh://user@host/~/git/client1.git
Here is my local client config:
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
precomposeunicode = true
[remote "framework"]
url = ssh://user@host/~/git/framework.git
fetch = +refs/heads/*:refs/remotes/framework/*
[remote "client"]
url = ssh://user@host/~/git/client1.git
fetch = +refs/heads/*:refs/remotes/client/*
For your pattern, you can declare one of the repositories read-only, as per this answer (several suggestions). Then you can use git pull client
and git pull framework
to sync up, and git push client
to push your code. To set client
as your default remote, you can do git branch --set-upstream-to client/master
(or replace master with whatever remote branch you want to push to by default).
A more common pattern is to use branches to keep framework and client separate. This also means you need only two repositories: your shared bare repository, and your local development one. You can pull from origin
, which has main two branches, framework
and client
. You can choose what to merge from framework
into client
, and you'd (almost) never merge from client
back to framework
.
这篇关于从多个拉,只推一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!