更新时间:2023-11-30 14:11:58
为了从现有的仓库创建一个新的Git仓库,通常会创建一个新的仓库,并将一个或多个分支从现有仓库推送到新的仓库。
以下步骤说明了这一点:
创建一个新的存储库。它必须是裸露的为了您推它。
$ mkdir /路径/到/ new_repo
$ cd / path / to / new_repo
$ git --bare init
:确保您的新存储库可从现有存储库访问。有很多方法可以做到这一点;假设您通过 ssh:// my_host / new_repo
来访问它。 推送a从现有的存储库分支。例如,假设我们希望从现有存储库中推送分支 topic1
,并在新存储库中将其命名为 master
。
$ cd / path / to / existing_repo
$ git push ssh:// my_host / new_repo + topic1:master
这项技术可让您保留现有分支的历史记录。
I have a remote git repository that really replaced everything we had in another older SCM. Many projects and products have been added to the repository over the years.
There is a branch in this repo, corresponding to a product that I am interested in. I want to make a brand new git repository from this branch only, not really concerned about loss of history.
Is git remote add the solution? I want for both of these repositories to be on the same server.
Thoughts?
In order to create a new Git repository from an existing repository one would typically create a new bare repository and push one or more branches from the existing to the new repository.
The following steps illustrates this:
Create a new repository. It must be bare in order for you to push to it.
$ mkdir /path/to/new_repo
$ cd /path/to/new_repo
$ git --bare init
Note: ensure that your new repository is accessible from the existing repository. There are many ways to do this; let's assume that you have made it accessible via ssh://my_host/new_repo
.
Push a branch from your existing repository. For example let's say we want to push the branch topic1
from the existing repository and name it master
in the new repository.
$ cd /path/to/existing_repo
$ git push ssh://my_host/new_repo +topic1:master
This technique allows you to keep the history from the existing branch.