Moving Repositories
Follow the steps below to move a full Git repository, with history, from one remote server to another. You can move an entire repository or allow choose which branches and tags to include.
For the sake of this tutorial, the original repository will be https://github.rcac.purdue.edu/foo/bar
and it will be moving to https://github.itap.purdue.edu/foo/bar
.
1) Create an empty repo on the new Git server:
You need to have an empty target repository to push your cloned repository to. Do not add any of the suggested README
or LICENSE
auto-generated files as they will not be needed.
Link to section 'Entire Repository' of 'Moving Repositories' Entire Repository
If you want to copy the entire repository you can use the following steps instead.
2) Create a local repository. In this example, we're cloning into a directory called temp-dir
:
git clone --mirror https://github.rcac.purdue.edu/foo/bar temp-dir
Note: git clone –mirror
implies –bare
and does not generate a working copy.
3) Go into the temp-dir
directory.
cd temp-dir
4) Link your local repository to the newly created repository using the following command:
git remote set-url origin https://github.itap.purdue.edu/foo/bar
5) Push all branches and tags:
git push --mirror https://github.itap.purdue.edu/foo/bar
A Note on Pull Refs
When migrating a repo, you may errors like the following:
! [remote rejected] refs/pull/100/head -> refs/pull/100/head (deny updating a hidden ref)
! [remote rejected] refs/pull/101/head -> refs/pull/101/head (deny updating a hidden ref)
You will see this refs/pull
errors if your repository has ever had a Pull Request. refs/pull
is a private, read-only ref created by GitHub, in part, to allow for linking back to a Pull Request and its discussion thread, etc. These references cannot be mirrored but they do not prevent mirroring the rest of the repo and its history. These errors can be safely ignored.
Link to section 'Selective Branches' of 'Moving Repositories' Selective Branches
2) Create a local repository. In this example, we're cloning into a directory called temp-dir
:
git clone https://github.rcac.purdue.edu/foo/bar temp-dir
3) Go into the temp-dir
directory.
cd temp-dir
4) To see available branches of https://github.rcac.purdue.edu/foo/bar
:
git branch -a
5) Checkout all the branches that you want to copy:
git checkout branch-name
6) Fetch all the tags from https://github.rcac.purdue.edu/foo/bar
:
git fetch --tags
7) Check that your local branches and tags look correct:
git tag
git branch -a
8) Link your local repository to the newly created repository using the following command:
git remote set-url origin https://github.itap.purdue.edu/foo/bar
9) Push all branches and tags:
git push origin --all
git push --tags
There should now be a full copy of the repository at https://github.itap.purdue.edu/foo/bar
.
It's a good idea to archive the old repository at https://github.rcac.purdue.edu/foo/bar
to avoid having other users making commits to the old repository. See below for more information on how to archive a repository on GitHub.
Link to section 'Moving GitHub Wikis' of 'Moving Repositories' Moving GitHub Wikis
You can also migrate GitHub wikis using the above procedure because wikis are simply Git repositories that follow the special naming convention [repo-name].wiki.git
. As with repositories, an empty wiki at the destination (e.g., https://github.itap.purdue.edu/[owner]/[repo-name]/wiki
) must first be created before you try pushing to it.
Link to section 'Archiving GitHub repositories' of 'Moving Repositories' Archiving GitHub repositories
Archiving a repository lets users know that the repository is no longer used. When archiving a repository, all of its issues, pull requests, code, labels, milestones, projects, wiki, releases, commits, tags, branches, reactions, and comments become read-only. To make any changes to an archived repository it must be unarchived first.
To archive a repository, navigate to the main page of the repository and click the Settings
tab for the repository. Scroll down and find the Danger Zone
where you should click the Archive this repository
button. Read the warnings and type the name of the repository foo/bar
in the confirmation box and click the button to archive the repository.
To unarchive a repository, follow the same instructions as archiving the repository, all the buttons will be replaced with ones to unarchive the repository.
For more information about archiving repositories you can visit GitHub's documentation and click the button to archive the repository.