Best way to maintain a Git fork

1.6k views Asked by At

Company ACME keeps a product X that we extend and customize. They have made their git repository visible to us, but we can't write to it. ACME is using their own internal Git server with Gitolite.

Our developers want to write to it, so we need a local copy. However, I'd be nice to keep the Commit history from Company ACME. Is there a way to do it? Also, how should I go about updating our code with code from Company ACME? We are using Github Enterprise.

The way I was thinking loses the history from Company ACME.

  1. Clone repository X into a Staging folder. Keep this repository up to date from Company ACME.
  2. Create new repository Y for our use.
  3. Create branch in Repository Y for "Original" code. Developers would branch or fork from this.
  4. Manually copy the files from Repository X into "Original" branch of Repository Y.

There must be a best way. I essentially want to make a local fork and keep it updated while still giving our developers access to commit code.

2

There are 2 answers

1
axd On BEST ANSWER

this is called the "vendor branch" pattern. (consider adding those SO tags to your post.)

you can also embed the ACME artefacts in your rep: the original, unchanged ACME code will live on its own (so-called "vendor"-) branch, and will be merged to 'master' or wherever you need it.

whenever ACME changes code, you checkout the ACME vendor branch and store the updates there, tag with the vendor tag (this eases seeing what versions of ACME are in house), and merge the changes where needed.

Edit added: Once you understand this mechanism, take a look at the subtree merge mechanism.

2
Pedram On

In my opinion you can fork the ACME repository. So now you have write access to your forked repository (or local clone).

Now you can create a new branch in this local repository to continue your development while still having kept the master branch (or renaming it to whatever suits your needs) linked with the original readonly repository.

Doing this, whenever you need to update your code to the latest developments made in the ACME repository, you can simply pull their changes from that remote and merge them to your development branch. There is no need to create several copies of that repository.