Skip to content

Activity 3: Graft a repository #4

@selkins13

Description

@selkins13

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions