简体   繁体   中英

Is it possible to maintain a same git project on two different remotes (private and public) with different commit history?

I have been working on a private repository, where the project has initially been created with some sensible data. Now that I have enough content on the project I'd like to make it public on Github.

The work is still on-going and I'd like to avoid to maintain two different repositories.

The idea would be to have
在此处输入图片说明

From commit 29 everything would remain in sync (private and public).

From what I've read

This seems to be impossible based on the way Git works (cf. Based on this answer )

But

Could it be possible to fiddle around with the git hooks from my private repository to push to github ?

SO references

Managing a private and public remote with different histories
Import existing source code to GitHub
Resetting remote to a certain commit
Maintain a private and a public repo simultaneously using git branch with two different clouds
GitHub: How to make a fork of public repository private?

You can use an orphaned branch to achieve this:

# Suppose the tip of master has everything you want to start out as
# the initial commit in github
git checkout master
git remote add github <url to the project>
git checkout --orphan public
git push --set-upstream github public

Now effectively you have two repos in your local repo, pointed to by public and master . They are unrelated, so you won't be able to merge either way. You can copy commits between them using cherry-pick or patches however.

If you wish to continue to use master for future development, simply do:

git checkout master
git branch master-archived
git reset --hard public

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM