简体   繁体   English

维护 git 存储库的克隆

[英]Maintaining a clone of a git repository

I want to make a clone of a github repostitory in a (self-hosted) bitbucket server and from time to time pull the latest changes from the github repository.我想在(自托管)bitbucket 服务器中克隆 github 存储库,并不时从 github 存储库中提取最新更改。 In our clone we're going to do some experimental stuff which will never leave our repository.在我们的克隆中,我们将做一些永远不会离开我们的存储库的实验性内容。

To illustrate;为了显示; with fossil I'd make sure that our repository and their repository has the same project id, and I'd do this:对于fossil,我会确保我们的存储库和他们的存储库具有相同的项目ID,我会这样做:

$ cd ~/checkout/prjdir
$ fossil pull https://their.org/prj/foo --once

This would get all the latest checkins, branches, tags, etc. And then to push it to our organization's server:这将获得所有最新的签入、分支、标签等。然后将其推送到我们组织的服务器:

$ fossil push

There will never be any conflicts;永远不会有任何冲突; our changes will be made on experimental branches so there's no need for any merges when updating from upstream.我们的更改将在实验分支上进行,因此从上游更新时无需任何合并。

I've tried to replicate the fossil workflow and copy/pasted some things which seem relevant and come up with this for the initial cloning:我尝试复制化石工作流程并复制/粘贴一些似乎相关的内容,并为初始克隆提出以下建议:

$ git clone https://github.com/foo/bar.git
$ cd bar
$ git remote set-url origin https://ourbitbucket.org/foo/bar.git
$ git push -u origin master

This however doesn't appear to have brought with it the tags (tags are important to us).然而,这似乎并没有带来标签(标签对我们很重要)。

With git (github as upstream and our bitbucket server for our own tags/branches):使用 git(github 作为上游,我们的 bitbucket 服务器用于我们自己的标签/分支):

  1. how do I make a complete clone of a repository (including all branches and tags)?如何制作存储库的完整克隆(包括所有分支和标签)?
  2. once I have a cloned repository, how do I pull all the latest changes (branches, tags included) from upstream (on github) and push them to our server (bitbucket)?一旦我有一个克隆的存储库,我如何从上游(在 github 上)提取所有最新的更改(包括分支、标签)并将它们推送到我们的服务器(bitbucket)?

Don't change the URL of the repository.不要更改存储库的 URL。 Just create two remotes, upstream and origin .只需创建两个遥控器, upstreamorigin

Tags aren't pushed by default.默认情况下不推送标签。 Use --tags to push them.使用--tags来推送它们。

$ git clone https://github.com/foo/bar.git
$ cd bar
$ git remote rename origin upstream
$ git remote add origin https://ourbitbucket.org/foo/bar.git
$ git push -u --tags origin master

Whenever you want to synchronize with the upstream, do每当您想与上游同步时,请执行

$ git checkout master
$ git pull upstream master

or even甚至

$ git reset --hard upstream/master

and rebase your branch (or merge master into it) to incorporate their changes into your work:并重新设置您的分支(或将 master 合并到其中)以将他们的更改合并到您的工作中:

$ git checkout my-branch
$ git rebase master

or或者

$ git checkout my-branch
$ git merge master

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM