Migrate a GitHub LFS (Git Large File Storage) repository to AWS CodeCommit
- Tan Shuai
- Software Development
- 09 Feb, 2022
I recently migrated one of my GitHub repositories, which uses Git Large File Storage (LFS), over to AWS CodeCommit. I thought I'd share the process with you in case you’re looking to do something similar. Here's a step-by-step guide based on my experience.
Prerequisites
Before we get started, make sure you have these tools installed:
- Git
- Git LFS
- AWS CLI
Step-by-Step Guide
1. Clone the Repository
First, clone your GitHub repository using the --mirror
option. This creates a bare clone of the repository, including all branches and tags.
git clone --mirror https://github.com/tanshuai/designs.git designs
2. Verify LFS Files
Next, list all files managed by Git LFS to ensure everything is in place.
git lfs ls-files
You should see something like this:
cadfa0bc9e * Brochure-Trifold-Draft.ai
af9b8b8a1c * Brochure-Trifold-English.ai
27bb5f4e61 * Brochure-Trifold.ai
3. Migrate LFS Files
Now, export the LFS files. This step makes sure they are part of your repository’s history.
git lfs migrate export --include="*.ai" --everything
You'll see some progress messages like these:
migrate: Sorting commits: ..., done.
migrate: Rewriting commits: 100% (20/20), done.
master 98a3c48d85... -> 82f8873b41...
migrate: Updating refs: ..., done.
migrate: checkout: ..., done.
prune: 3 local object(s), 0 retained, done.
cadfa0bc9e... (133 MB)
27bb5f4e61... (131 MB)
af9b8b8a1c... (130 MB), done.
prune: Deleting objects: 100% (3/3), done.
4. Clean Up LFS
Remove the Git LFS tracking information and uninstall Git LFS.
git lfs ls-files
git rm .gitattributes -f
git lfs uninstall
5. Push to AWS CodeCommit
Finally, push your repository to AWS CodeCommit.
git push https://git-codecommit.us-east-2.amazonaws.com/v1/repos/designs --all
That’s it! By following these steps, I successfully migrated my GitHub LFS repository to AWS CodeCommit. The large files and the repository history were preserved perfectly.
Wrapping Up
Migrating a GitHub repository that uses Git LFS to AWS CodeCommit is pretty straightforward if you follow the right steps. If you have any questions or run into issues, the AWS CodeCommit documentation and Git LFS documentation are great resources.
I hope you find this guide helpful. Happy coding!