Skip to content

Instantly share code, notes, and snippets.

@JJL772
Created March 5, 2023 09:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JJL772/58097d7641878eda812063d4b39f5853 to your computer and use it in GitHub Desktop.
Save JJL772/58097d7641878eda812063d4b39f5853 to your computer and use it in GitHub Desktop.
git repo migration notes

Steps for migrating Git repos (including LFS objects) to GitHub

Documents the steps taken to migrate P2CE's internal git repos to github with self-hosted LFS storage (literally just a gitlab instance lol).

Step 1: Mirror LFS Contents (Do this first!)

This is done first because LFS is entirely separate from the git repo itself. Relying on .lfsconfig makes it a bit tricky to mirror using "standard" procedures since there's typically no working tree available.

  1. Clone your repo
  2. Run git lfs fetch --all. We'll need all LFS objects here!
  3. Create LFS storage repo somewhere. We just need an endpoint that implements the git LFS api (GitLab, .
  4. Put the following in .lfsconfig:
[lfs]
        pushurl = https://git.example.org/me/myrepo-lfs.git/info/lfs
  1. Commit your .lfsconfig and push to the old remote.
  2. Run git lfs push --all <remote> <branch> This will upload your LFS objects to the specified mirror. NOTE: remote and branch do not matter at all here, just use origin master or whatever.

Step 2: Mirror Git Contents

This will actually migrate your git repo!

  1. Clone bare repo: git clone --bare <your url>
  2. cd into repo: cd <your repo>
  3. Push git contents: git push --mirror https://github.com/my-repo.git

--mirror here will tell git to upload everything it can from the old remote. Branches and other refs will be pushed.

Issues and Solutions

LFS upload fails with TCP timeout or HTTP 524

If you're using cloudflare do not proxy your LFS git server.

HTTP 404 on some objects when mirroring

You didn't fetch absolutely all of the LFS objects, repeat the git lfs fetch --all and git lfs push --all steps. I've had this happen inexpicably, repeating those steps tends to fix it.

Some branches are not pushed to the new repo

This can happen if you're trying to mirror from a full clone with more than 1 remote. Just make a bare clone and mirror from that as described in step 2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment