Activity 3: Graft a repository
Opened this issue · 5 comments
Duration: 20 minutes
Grafting commands
- Step 1: Clean your repository
- LFS
- Unneeded or unwanted files
- Add dependencies to dependency management
- Remove independent components
- Remove any binaries
- Review automation in the repository
- Step 2: Create a new repository
- Step 3: Prepare for grafting
- Communicate properly to the affected teams
- Merge all in progress work
- If something is not merged, it will not be moved
- Call GitHub Professional Services if things go south
- Step 4: Delete your history
# Delete the git folder that contains git objects
rm -rf .git
# Initialize a new history
git init
# Set the new repository
git remote add origin git@github.com:githubuniverseworkshops/grafting-repo.git
- Step 5: Write a commit referencing to the previous repository as your first commit in the new repository
# Add all files to the stage
git add --all
# Add changes to history
git commit -m "Previous repo can be found on https://github.com/torvalds/linux"
# Submit your changes to upstream
git push --set-upstream origin main
Working with the new repository
To preserve the history while working with the new repository, follow the grafting command:
# Fetch the old history
git fetch git@github.com:torvalds/linux.git
# See you only have one commit in it
git log --oneline
# See the commits we are replacing
git rev-parse --short HEAD
git rev-parse --short FETCH_HEAD
# Perform the grafting operation replacing HEAD with FETCH_HEAD
git replace HEAD FETCH_HEAD
Check that all the changes that have happened to the repository are local and don't get pushed when new code goes to the repository:
# Check that the new commit goes to the right repo
# Modify a file
echo "Test" > test.txt
git add --all
git commit -m "Adding a test commit"
# Check that you can navigate the history
git log --oneline | head -n 10
# Push the change and see the number of commits is still 2
git push
Analysis after grafting
Re-run the command from Activity 2 to analyze the grafted repository.
Stats of repo size: git-sizer
- Download the corresponding compiled version of
git-sizer
.
Optionally you can install git-sizer using Homebrew if you are on Mac.
- Run the tool from the root of the repository to analyze:
/path/to/git-sizer --verbose
Find files that should be in LFS: git-find-lfs-extensions
- Checkout the
grafting-monorepos
repository - Run the tool from the root of the repository to analyze:
/path/to/grafting-monorepos/scripts/git-find-lfs-extensions
Print directories with the number of files contained: git-find-dirs-many-files
- Checkout the
grafting-monorepos
repository - Run the tool from the root of the repository to analyze:
/path/to/grafting-monorepos/scripts/git-find-dirs-many-files
Find dirs that should not be committed: git-find-dirs-unwanted
- Checkout the
grafting-monorepos
repository - Run the tool from the root of the repository to analyze:
/path/to/grafting-monorepos/scripts/git-find-dirs-unwanted | head -n 15
Analyze the repository: git-filter-repo --analyze
- Clone the
git-filter-repo
tool - Execute the tool from the linux repository
/path/to/git-filter-repo/git-filter-repo --analyze
For examples and more information, please see README.md -> Activity 3.
It sounds like that there is the assumption that everything is merged into the main
branch but what about existing bug-fix/release branches which still need to be maintained? 🚀
@TestStefan Very good question! This approach only covers merged changes. Unmerged branches need a special treatment that is outside the scope of this workshop. But we can help with that in a Professional Services session.
@TestStefan Very good question! This approach only covers merged changes. Unmerged branches need a special treatment that is outside the scope of this workshop. But we can help with that in a Professional Services session.
I guess you need to cleanup all active branches and create in the new grafted repository these branches as well and link them back to the archive repository.
After run the command "git push --set-upstream origin main" I got the fellowing error(I am using windows 10)
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Any suggestion to fix it? Thanks
Any clear instruction for step 1: Clean your repository: how to make it ?
LFS
Unneeded or unwanted files
Add dependencies to dependency management
Remove independent components
Remove any binaries
Review automation in the repository
If you could provide a video demo using a public example?
Many thanks.