Welcome to MLink Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

github - Best way to set up a git repo using another git repo

This one is a little complicated in what I'm trying to ask, so please bear with me.

There exists a public git repo, let's call it 'repoA'. It has a branch 'master'. I have my own copy of the code (not forked, just downloaded and copied). I have set up my own separate repo using this code, call it 'repoB' (a non-public repo), branch master.

I work on the master branch of the code from repoB, and I have no issue making changes to the code, pulling and pushing to repoB. However, now and then, the person working on repoA may make a change to the code, add new code etc, that I want to have in my master branch from repoB that I work on. I would ideally like to merge the changes into master on repoB from repoA, with any conflicting changes defaulting to preserving my code in repoB if such a conflict occurs.

I was wondering if there was a sensible way of setting this up, and how I would go about doing so. The only work around I could think of was to manually copy repoA's master branch into a separate branch, 'branch2', on repoB everytime repoA is updated, and then merge the 2 branches. However, this sounds very long winded, and I was wondering if there is a smarter way to go about doing this.

Cheers


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You could setup repoA as upstream and repoB as origin. To prevent pushes to repoA, set push url to a dummy one using git remote set-url --push upstream dummy_url

This allows you to pull the code from repoA and push to repoB. In repoB, leave master branch as it is and have an integrated-master branch that can be used to merge your changes with the repoA master changes for integrated testing.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to MLink Developer Q&A Community for programmer and developer-Open, Learning and Share
...