简体   繁体   中英

Branch a public git repository, on a private git server

I have my own git server on a local Fedora machine. I have two development machines, a local Fedora machine, and a local Windows 7 machine. (Both development machines and the git server are all on a local network, so I'll get faster speeds this way than using github.)

There is a github repository of a BSD-licensed library that I use. I would like to make my own changes that I can push to my own git server, with the option of submitting SOME but not all patches or pushes to github.

I'd like to be able to have my local repository be able to pull changes made from the github repository. (I know I may have to do manual merges, if the github repository changes around where I make my local changes.)

How can I do this?

I have been periodically updating from the github repository, adding that directory to my local git server as a new repository, re-making any changes, and pushing to my local git server.

There has to be a better way.

Git is distributed, so the workflow you describe is essentially how Git works anyway.

Let's first consider that you don't want to submit your changes back. Then you can just git clone the remote server, git remote add your private server and push to it. When upstream has new stuff you want, git pull from it, and when you have anything new, git push to your private server. In this workflow, the commits on your private server and the public ones are the same (same sha1 in particular), but your private server has some commits that the public server does not have.

Using git clone on the first and git remote add the other or vice versa doesn't change much. git clone configures the default upstream (so that argumentless git pull and git push synchronize with that remote), so the simplest is to git clone from the remote you use most often. But you can change the default upstream later (eg git push --set-upstream ).

Suggested reading: Working with remotes .

Now, if you want to submit changes to upstream, the difficulty is that you can't just push a branch to github. Actually, you may have some changes to be submitted on top of some changes you want to keep private, hence the submission has to involve some kind of merge, and possibly conflict resolution. You can do this by creating a branch like for-github (branched from the tip of the public history), and git cherry-pick the changes you want to contribute to this branch. Then, push this branch to github. Possibly better: for each feature you want to contribute upstream, create a branch for this feature, cherry-pick the relevant commits, push and make a pull-request on github.

Suggested reading: git cherry-pick .

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