0%

Git仓库迁移

有的时候,我们需要将代码仓库从一个地方迁移到另外一个地方,下面是迁移的方法。

仓库迁移

假如要将giteeold-account账户下的test项目迁移到githubnew-account账户下

1
2
3
git clone --bare git@gitee.com:old-account/test.git
cd test.git/
git push --mirror git@github.com:new-account/test.git

命令说明

git clone –bare

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
NAME
git-clone - Clone a repository into a new directory

SYNOPSIS
git clone [--template=<template_directory>]
[-l] [-s] [--no-hardlinks] [-q] [-n] [--bare] [--mirror]
[-o <name>] [-b <name>] [-u <upload-pack>] [--reference <repository>]
[--separate-git-dir <git dir>]
[--depth <depth>] [--[no-]single-branch]
[--recursive | --recurse-submodules] [--] <repository>
[<directory>]

OPTIONS

--bare
Make a bare Git repository. That is, instead of creating <directory> and placing the administrative files in <directory>/.git, make the <directory> itself the $GIT_DIR. This obviously implies the -n because there is nowhere to check out the working
tree. Also the branch heads at the remote are copied directly to corresponding local branch heads, without mapping them to refs/remotes/origin/. When this option is used, neither remote-tracking branches nor the related configuration variables are
created.

git push –mirror

1
2
3
4
5
6
7
8
9
10
11
12
NAME
git-push - Update remote refs along with associated objects

SYNOPSIS
git push [--all | --mirror | --tags] [--follow-tags] [-n | --dry-run] [--receive-pack=<git-receive-pack>]
[--repo=<repository>] [-f | --force] [--prune] [-v | --verbose] [-u | --set-upstream]
[<repository> [<refspec>...]]

OPTIONS
--mirror
Instead of naming each ref to push, specifies that all refs under refs/ (which includes but is not limited to refs/heads/, refs/remotes/, and refs/tags/) be mirrored to the remote repository. Newly created local refs will be pushed to the remote end,
locally updated refs will be force updated on the remote end, and deleted refs will be removed from the remote end. This is the default if the configuration option remote.<remote>.mirror is set.