【问题标题】:Merging remote content to local repo将远程内容合并到本地仓库
【发布时间】:2012-10-22 14:57:43
【问题描述】:

我正在尝试将远程存储库克隆到我的本地工作区,并将内容推送到我设置维护的新裸存储库,此存储库需要不时从上游存储库更新,并且需要将新内容推送到本地仓库也是如此。

这是一个例子:

git clone ssh://username@whatevergitrepo.com/project

我创建了一个裸仓库作为 project_local

mkdir project_local.git
git init --bare --share=2 project_local.git

一旦远程仓库被克隆到我的工作区,由于这个远程仓库有多个分支,

branch1
branch2
.
.
branchN

这是我从远程获取所有分支并推送到本地裸仓库的操作。

cd project
git branch -a >&/tmp/branchinfo
sed s,.*/,, /tmp/branchinfo >&/tmp/branchinfo1                              #this remove everything before the last '/' before the actual name of the branch
for i in `cat /tmp/branchinfo1`; do git checkout $i; done                   #checkout all the branches from remote site.
for i in `cat /tmp/branchinfo1`; do git push project_local.git $i; done     # Push all the remote branches to local repo I created with all contents.

在此之后,来自远程仓库的内容现在位于我的本地裸仓库中,但是如何获取各个分支的所有远程更改并将其合并到我创建的本地仓库中的相应分支?

我尝试过使用“git remote add”,但它只获取引用,实际上并没有合并内容。

提前感谢您为我提供的任何帮助。

谢谢

【问题讨论】:

  • 添加遥控器后你拉了吗?此外,如果您正确配置了遥控器,我相信当您执行“git push”时,所有跟踪的分支都会被同时推送
  • 我做了一个拉,但它告诉我配置不正确,推送不起作用,我怎样才能正确设置配置文件,对不起,如果这个问题看起来有点愚蠢,但我是新手混帐。谢谢

标签: git version-control git-merge git-remote


【解决方案1】:

听起来你所做的只是更新分支。除非您计算一个实际上只是参考更新的快进合并,否则没有合并。

你需要做的就是

git fetch original-repo
git branch -r | cut -f3- -d'/' | xargs -i{} git push new-repo original-repo/{}:{}

这假设您已经为您的新仓库添加了一个远程条目并将其命名为new-repo

【讨论】:

  • 非常感谢,我试试看。顺便说一句,我已将远程添加为上游,执行 'git remote add upstream ssh://username@whatevergitrepo.com/project'
猜你喜欢
  • 2018-12-14
  • 1970-01-01
  • 1970-01-01
  • 2016-10-09
  • 1970-01-01
  • 2021-04-07
  • 2018-12-05
  • 2012-06-26
相关资源
最近更新 更多