sh 将git存储库及其所有分支,标记移动到新的远程存储库,保留提交历史记录

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh 将git存储库及其所有分支,标记移动到新的远程存储库,保留提交历史记录相关的知识,希望对你有一定的参考价值。

#!/bin/bash
# Sometimes you need to move your existing git repository
# to a new remote repository (/new remote origin).
# Here are a simple and quick steps that does exactly this.
#
# Let's assume we call "old repo" the repository you wish
# to move, and "new repo" the one you wish to move to.
#
### Step 1. Make sure you have a local copy of all "old repo"
### branches and tags.
# Fetch all of the remote branches and tags:
git fetch origin

# View all "old repo" local and remote branches:
git branch -a

# If some of the remotes/ branches doesn't have a local copy,
# checkout to create a local copy of the missing ones:
git checkout -b <branch> origin/<branch>

# Now we have to have all remote branches locally.


### Step 2. Add a "new repo" as a new remote origin:
git remote add new-origin git@github.com:user/repo.git


### Step 3. Push all local branches and tags to a "new repo".
# Push all local branches (note we're pushing to new-origin):
git push --all new-origin

# Push all tags:
git push --tags new-origin


### Step 4. Remove "old repo" origin and its dependencies.
# View existing remotes (you'll see 2 remotes for both fetch and push)
git remote -v

# Remove "old repo" remote:
git remote rm origin

# Rename "new repo" remote into just 'origin':
git remote rename new-origin origin


### Done! Now your local git repo is connected to "new repo" remote
### which has all the branches, tags and commits history.

以上是关于sh 将git存储库及其所有分支,标记移动到新的远程存储库,保留提交历史记录的主要内容,如果未能解决你的问题,请参考以下文章

sh 如何将新的本地分支推送到远程Git存储库并跟踪它?

如何将包含所有分支的 Git 存储库从 Bitbucket 移动到 GitHub?

sh 将所有未提交的更改移动到新分支,并将现有分支恢复为HEAD。“master”具有未提交的更改。你决定了

如何将旧提交从旧存储库移动到新存储库

sh 从git存储库中删除所有标记(本地和远程)

将整个开发分支重新定位到新的主分支