GitBucket
4.21.2
Toggle navigation
Snippets
Sign in
Files
Branches
1
Releases
Wiki
nigel.stanger
/
Wiki
Compare Revisions
View Page
Back to Page History
Freaky Git stuff.md
## LFS To migrate a large repository to LFS in GitBucket: 1. Create a new repository `newrepo` on the server by cloning the old one. 1. Clone `newrepo` to local. 1. Initialise `git-lfs` in `newrepo` as per the [git-lfs tutorial](https://github.com/git-lfs/git-lfs/wiki/Tutorial#adding-git-lfs-to-a-pre-existing-repo): ```sh git lfs track "*.thing1" "*.thing2" git add .gitattributes git commit -m "Track thing1, thing2 files (LFS)" git rm --cached "*.thing1" "*.thing2" git add . git commit -m "Convert last commit to LFS" ``` 1. Migrate the history as per the [git-lfs tutorial](https://github.com/git-lfs/git-lfs/wiki/Tutorial#migrating-existing-repository-data-to-lfs): ```sh git lfs migrate import --everything --include="*.thing1,*.thing2" ``` If you specify multiple `--include` switches only the last one will take effect, so to migrate multiple file types, put the glob expressions inside the same string as shown above. 1. We now need to force push `newrepo` to remote, but it may be too large for nginx’s request size limits. If you happen to have release tags handily scattered throughout history (or you can identify some well-spaced commit hashes) you can reduce the request size by only [pushing up to a certain commit](https://coderwall.com/p/hexinq/git-push-up-to-a-certain-commit), e.g.: ```sh git push --force origin 9d42ad26508d94429ce2179358db5c2bfc1dc03d:master # ...etc... # one last push to catch everything since the last tag: git push --force ``` Do this for each of the tags/commits in chronological order. You can find the commit hashes for the tags using `git show-ref --tags`. 1. Also force push the rewritten tags to prevent push/pull errors due to the different commit hashes: ```sh git push --force --tags ``` 1. Clean up local as per the [git-lfs tutorial](https://github.com/git-lfs/git-lfs/wiki/Tutorial#cleaning-up-the-git-directory-after-migrating): ```sh git reflog expire --expire-unreachable=now --all git gc --prune=now ``` ## Finding repositories that haven’t been pushed Something along these lines (from comments on <https://stackoverflow.com/a/12499489>): ```sh find . -name .git -type d -print -exec git --git-dir={} --work-tree={}/.. cherry -v \; ``` ## Migrate a wiki repo to another GitBucket server 1. Clone the original repository that contains the wiki (`old-repo`). 1. Clone the actual wiki itself (`old-wiki`). 1. Create empty `new-repo` on new server. 1. Transfer ownership of `new-repo` if necessary. **Do this before any of the remaining steps.** 1. In `old-repo` clone: ```sh git remote set-url origin <new-repo-url> git push ``` 1. In `old-wiki` clone: ```sh git remote set-url origin <new-wiki-url> git push -f ``` 1. Update wiki link in `README.md` of `new-repo`. 1. Profit!
## LFS To migrate a large repository to LFS in GitBucket: 1. Create a new repository `newrepo` on the server by cloning the old one. 1. Clone `newrepo` to local. 1. Initialise `git-lfs` in `newrepo` as per the [git-lfs tutorial](https://github.com/git-lfs/git-lfs/wiki/Tutorial#adding-git-lfs-to-a-pre-existing-repo): ```sh git lfs track "*.thing1" "*.thing2" git add .gitattributes git commit -m "Track thing1, thing2 files (LFS)" git rm --cached "*.thing1" "*.thing2" git add . git commit -m "Convert last commit to LFS" ``` 1. Migrate the history as per the [git-lfs tutorial](https://github.com/git-lfs/git-lfs/wiki/Tutorial#migrating-existing-repository-data-to-lfs): ```sh git lfs migrate import --everything --include="*.thing1,*.thing2" ``` If you specify multiple `--include` switches only the last one will take effect, so to migrate multiple file types, put the glob expressions inside the same string as shown above. 1. We now need to force push `newrepo` to remote, but it may be too large for nginx’s request size limits. If you happen to have release tags handily scattered throughout history (or you can identify some well-spaced commit hashes) you can reduce the request size by only [pushing up to a certain commit](https://coderwall.com/p/hexinq/git-push-up-to-a-certain-commit), e.g.: ```sh git push --force origin 9d42ad26508d94429ce2179358db5c2bfc1dc03d:master # ...etc... # one last push to catch everything since the last tag: git push --force ``` Do this for each of the tags/commits in chronological order. You can find the commit hashes for the tags using `git show-ref --tags`. 1. Also force push the rewritten tags to prevent push/pull errors due to the different commit hashes: ```sh git push --force --tags ``` 1. Clean up local as per the [git-lfs tutorial](https://github.com/git-lfs/git-lfs/wiki/Tutorial#cleaning-up-the-git-directory-after-migrating): ```sh git reflog expire --expire-unreachable=now --all git gc --prune=now ``` ## Finding repositories that haven’t been pushed Something along these lines (from comments on <https://stackoverflow.com/a/12499489>): ```sh find . -name .git -type d -print -exec git --git-dir={} --work-tree={}/.. cherry -v \; ```