Here's one approach:
- Checkout the source branch
- Switch to a new branch in the existing repo, e.g.
git switch -c beautiful_history_1
git rebase --interactive
- squash, remove, etc. shape the history to be what is desired
- Confirm the history and the code look the way you want it. If not just repeat steps 1-3.
- Change the directory and:
git clone <original_repo> --single-branch --branch beautiful_history_1
(you may also want --no-tags
)
Clone flags (from git-clone):
--no-tags
Don’t clone any tags, and set remote..tagOpt=--no-tags in the config, ensuring that future git pull and git fetch operations won’t follow any tags. Subsequent explicit tag fetches will still work, (see git-fetch[1]).
Can be used in conjunction with --single-branch to clone and maintain a branch with no references other than a single cloned branch. This is useful e.g. to maintain minimal clones of the default branch of some repository for search indexing.
--[no-]single-branch
Clone only the history leading to the tip of a single branch, either specified by the --branch option or the primary branch remote’s HEAD points at. Further fetches into the resulting repository will only update the remote-tracking branch for the branch this option was used for the initial cloning. If the HEAD at the remote did not point at any branch when --single-branch clone was made, no remote-tracking branch is created.