The current repository has commits
A -> B -> C
^
|
HEAD
I want to create a new repository whose master branch begins at commit C
(HEAD) of the current repository.
C
^
|
HEAD
Additionally, if a new commit D
is added to the current repository:
A -> B -> C -> D
^
|
HEAD
The new repository will become:
C -> D
^
|
HEAD
On the next push/mirror.
Due to learning to develop software while I committed changes to the project, the repository has gone in size due to large files being added and removed through it's long history (500 commits).
Can this workflow be easily achieved in git? (Using both GitHub and GitLab)
You can easily create a new repo from an existing one, at least locally: just git clone <src repo> [dest dir]
(possibly using --depth
or similar to save on size, though that comes with caveats, see the manual for details). Making that new repository automatically follow the original's history isn't going to be easy though. The new repo will have its origin
setup to point at the original, but updating will require a pull/fetch+merge/whatever as usual. You may be able to set up some post-commit hook in the old repo to automate the cd <new repo> ; git pull ; cd $OLDPWD
bit, I'm not well-versed in how git's hooks work. Alternately, you could set up the new repo as a remote in the old one and push to it, though I'm not sure how that'd affect the new repo's working tree (i.e., what's checked out). And making any of this work with a remote provider like GitHub would be an entirely different can of worms.
If you want to try cleaning up your history, you may want to look into rebase
and possibly cherry-pick
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With