Skip to content

Instantly share code, notes, and snippets.

@hectorddmx
Last active March 16, 2022 05:21
Show Gist options
  • Save hectorddmx/9602f678c777d38faeffb970f6c0d9ab to your computer and use it in GitHub Desktop.
Save hectorddmx/9602f678c777d38faeffb970f6c0d9ab to your computer and use it in GitHub Desktop.
Migrate self hosted repo with files bigger than 100 MB to github via git lfs
#!/bin/zsh
# Configure
CURRENT_ORG=SAMPLE_ORG
CURRENT_REPO=${PWD##*/}
# Track, fetch and pull all branches from previous host
git branch -r | grep -v '\->' | sed "s,\x1B\[[0-9;]*[a-zA-Z],,g" | while read remote; do git branch --track "${remote#origin/}" "$remote"; done
git fetch --all
git pull --all
# Adde new remote
git remote add github.com [email protected]:$CURRENT_ORG/$CURRENT_REPO
# Configure git lfs for this repo
git lfs install
# To review existing git lfs files
# git lfs ls-files
# To review files that will be migrated
# git lfs migrate info --everything --above=99Mb
git lfs migrate import --everything --above=99Mb
# First push for git lfs files
git push github.com --all --verbose --progress
# Second push to push all branches/tags
git push github.com --all --verbose --progress
# Upload all tags
git push github.com --tags --verbose --progress
# Make the console sound in macos to hear when it's finished
tput bel
@hectorddmx
Copy link
Author

Review if there are big files (no git lfs needed)

git rev-list --objects --all |
  git cat-file --batch-check='%(objecttype) %(objectname) %(objectsize) %(rest)' |
  sed -n 's/^blob //p' | awk '$2 >= 103809024' |
  sort --numeric-sort --key=2 |
  cut -c 1-12,41- |
  $(command -v gnumfmt || echo numfmt) --field=2 --to=iec-i --suffix=B --padding=7 --round=nearest

@hectorddmx
Copy link
Author

For future files

# Install git lfs in the current repo
git lfs install
# Add the following tracks
git lfs track "**/*.framework/**"
git lfs track "**/*.xcframework/**"
git lfs track "*.a"
git lfs track "*.pak"
git lfs track "*.dylib"
git lfs trakc "*.bin"
git lfs track "*.zip"
git lfs track "*.7z"
git lfs track "*.mp4"
git lfs track "*.png"
git lfs track "*.jpg"
git lfs track "*.jpeg"
git lfs track "*.sketch"
git lfs track "*.fig"

# If you have specific files that don't have an extension, you can add it with this command:
git lfs track --filename "Chromium Embedded Framework"

# Add to staging this new file called .gitattributes that contains the list of files that will be tracked:
git add .gitattributes

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