Skip to content

fix(git): enable use of --reference for sparse checkouts #354

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

Merged

Conversation

mastupristi
Copy link
Contributor

When using sparse checkouts, Gitman previously bypassed the local reference repository and treated it as a remote instead. This caused .git directories to become unnecessarily large, especially for repositories with extensive histories or LFS usage.

This commit updates the sparse checkout logic to:

  • initialize the working directory with git init
  • add the upstream repo as remote
  • set the alternates file to point to the local reference (if caching is enabled)
  • perform a sparse fetch and checkout using the actual origin

This restores object sharing via the local reference repository for sparse checkouts.

When using sparse checkouts, Gitman previously bypassed the local reference
repository and treated it as a remote instead. This caused `.git` directories
to become unnecessarily large, especially for repositories with extensive
histories or LFS usage.

This commit updates the sparse checkout logic to:
- initialize the working directory with `git init`
- add the upstream repo as remote
- set the `alternates` file to point to the local reference (if caching is enabled)
- perform a sparse fetch and checkout using the actual origin

This restores object sharing via the local reference repository for sparse checkouts.
Copy link
Owner

@jacebrowning jacebrowning left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@jacebrowning jacebrowning merged commit caaaad1 into jacebrowning:main Apr 24, 2025
6 checks passed
@mastupristi mastupristi deleted the feat/sparse-clone-with-reference branch April 26, 2025 09:37
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

Successfully merging this pull request may close these issues.

2 participants