Skip to content

Repository Migration

asgreen21 edited this page Dec 1, 2023 · 6 revisions

Git Migration

Here's one way to migrate from an existing git repository into GitHub.

  1. Create a New GitHub repository

    1. Leave this repository empty for now.

      https://github.com/The-Vanderbilt-University/vuit-repo-creation-iac

  2. Create a fresh clone of your old repository

    $ git clone --mirror <OLD PROJECT REPO >.git
    
  3. Change the remote to your new repo

    $ cd OLD_PROJECT_REPO_DIR
    $ git remote set-url origin <NEW PROJECT REPO>.git
    
  4. Push to GitHub

    NOTE: GitHub uses main as the default branch. Two options for importing are provided below.

    Change default branch from master to main (Recommended)

       $ git branch -m master main
       $ git push --mirror origin
    

    Keep original default branch (likely master)

       $ git push --mirror origin
    
    1. Navigate to your repo's settings and update your default branch.

What now?

All Tags and Branches?

The above migration process will include all branches and tags.

What about my old Repo?

Once the above steps are complete, your repository will exist in both places. You'll probably want to delete or archive your old repository to avoid confusion.

Change default branch after importing

If you'd like to change your default branch from master to main on an existing repo, follow these steps:

  1. Navigate to your repo's settings and update your default branch.

  2. Update master to main locally

   git branch -m master main
   git fetch origin
   git branch -u origin/main main
   git remote set-head origin -a

Clone this wiki locally