Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Activity 3: Graft a repository #4

Open
selkins13 opened this issue Dec 4, 2020 · 5 comments
Open

Activity 3: Graft a repository #4

selkins13 opened this issue Dec 4, 2020 · 5 comments

Comments

@selkins13
Copy link
Collaborator

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

  1. Download the corresponding compiled version of git-sizer.

Optionally you can install git-sizer using Homebrew if you are on Mac.

  1. 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

  1. Checkout the grafting-monorepos repository
  2. 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

  1. Checkout the grafting-monorepos repository
  2. 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

  1. Checkout the grafting-monorepos repository
  2. 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

  1. Clone the git-filter-repo tool
  2. 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.

@TestStefan
Copy link

TestStefan commented Dec 11, 2020

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? 🚀

@larsxschneider
Copy link
Collaborator

@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
Copy link

@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.

@neilwang0913
Copy link

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

@neilwang0913
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants