Briefly, the task is as follows: how to create a repository based on the contractor's repository, if further joint work on the project is planned?

Below are the details of the question.

Customer Organization. There is a server used as a git server on the Internet; no complex methodologies of working with git (like git-flow ) were used - the Shared Repository Model was enough. One master branch, into which all changes were injected - that’s the whole technique.

Contracting organization. In the Internet exhibited a server with gitlab on board. You can make a git clone to "see."

The question is how to be when the development is completed and it is time to transfer the project artifacts and raise the project on your own servers.

I want the following:

  • take the project completely to your server and work with it already
  • keep the entire history of the project by the contractor, and not start the repository from scratch
  • be able to synchronize repositories: so that contractors can pick up the current improvements from our git, so that we can pick up individual patches from their server.
  • one
    Please try to shorten the question, leaving only the key information. so that the question and its answers can be useful not only to you. - aleksandr barakin
  • Total, thoughtfully read everything, tested it. I find it difficult even to whom to put a daw, I always see both authors with sensible answers to stackoverflow, and on my question, they both helped me equally as well. KoVadim has well-defined schemes for working with pluses and minuses, it was a useful overview and reference to the “workflow with integration managers” model (from which, however, I didn’t get any details on how this is done). Alexander has more a constructor “collect yourself a suitable one” and very useful references to specifics, it was they who brought the general concept to a specific prototype. - AK
  • Below I add my answer: in fact, it's all the same, just much more. Perhaps someone else will come in handy. - AK

3 answers 3

In any case, someone must give someone access to the repository. But git is a git that allows you to use two remote repositories.

The first option . One (or several) "responsible for integration" is assigned. It should have access to both servers with git repositories. It will pull from both repositories, merdzhit and push back. You can read more here . If admins and bosses categorically do not allow releasing a git out (anything can happen), then this person can do it with a laptop and move between offices or use vpn.

If the changes will take place mainly on the one hand, the work will be very simple.

Pros :

  • repositories are easy to maintain in a consistent state
  • minimum handmade

Cons :

  • access needed
  • confidential information leakage is possible

The second way . Everyone has their own repository. When they make some changes (fix a bug), the patch is sent by mail (normal, electronic). And on the other side just applies. In git for this there is a whole set of tools and is quite well automated . In this scheme there should be at least two people - one who will form the patches and send them by mail, the other who will apply them.

Pros :

  • repositories are independent.
  • nobody knows what exactly is in someone else's repository.
  • you can apply selected patches
  • patches can be well analyzed

Cons :

  • repositories are likely to "go away."
  • a lot to do "pens"
  • I once read about the second method, but I would not seriously consider it. Although it did not even occur to me that this is also possible. The first option is curious, although I thought about the answers and clarified the details of the question - I realized that there is an opportunity to put a git server on the Internet (we will be able to exactly one thing), and therefore it will be possible to come up with a more convenient scheme. - AK
  • in any case, you can buy a repository on github and work calmly. - KoVadim

I tried to simulate the situation on two test repositories:

  • avn - repository, which is located at the contractor
  • fcs - the repository, which is located at the customer company

Repository model

There are two responsible for integration: one at the customer, one at the contractor.

We believe both repositories are available on the Internet for managers.


Phase 1. Development on the server of the contractor.

Fill in two or three commits to simulate how a contractor works:

 touch avn-file1.txt git add avn-file1.txt git commit -m "avn-file1.txt" ... touch avn-file3.txt git add avn-file3.txt git commit -m "avn-file3.txt" 

And periodically push them to the server.

At some point, the decision is made that the "hour X" has arrived and you can publish the project at the customer. Development stops, the contractor’s avn repository has a history of commits:

 pick fdf9508 avn-file1.txt pick 0633d9c avn-file2.txt pick 4d71f77 avn-file3.txt 

Phase 2. Creating your own repository based on the contractor's repository

We clone the contractor's repository and rewrite origin to the address of our own repository (edit the file /.git/config - well, or in a competent way: via git remote set-url origin <сервер заказчика> ), then git push -f .

We get an absolutely exact copy of the contractor's repository on our own server, with full preservation of the history and even SHA-1 commits will coincide:

 pick fdf9508 avn-file1.txt pick 0633d9c avn-file2.txt pick 4d71f77 avn-file3.txt 

We proceed to the next phase.

Phase 3. The customer performs some modifications at his own discretion and without regard for the former contractor.

Well, let's say, again, we create several commits:

 touch fcs-file1.txt git add fcs-file1.txt git commit -m "fcs-file1.txt" ... touch fcs-file3.txt git add fcs-file3.txt git commit -m "fcs-file3.txt" 

And we will periodically push them to our own server. (In reality, fcs is a bare-repository on a server that several developers at the client company have inclined to their workstations, but this is not critical for the test.)

We get this story on our server:

 pick fdf9508 avn-file1.txt pick 0633d9c avn-file2.txt pick 4d71f77 avn-file3.txt pick 7dd4772 fcs-file1.txt pick f33cdda fcs-file2.txt pick c54c562 fcs-file3.txt 

(The first three commits are those made by the contractor once, the next three are already the customer. The contractor still has only three commits in his repository)

And here at some point, the customer remembers about the contractor and gives him some task for revision. Further interaction proceeds according to the following scheme: a) the contractor takes away the changes made by the customer after the project is completed; b) the contractor makes some improvements in his repository; c) the customer takes the improvements to his server.

So, let's go:

Phase 4. Contractor picks up changes made by the customer

The contractor has some kind of employee responsible for integration, say, Vasya or Petya. Vasya in the avn repository (on his machine) connects the remote repository fcs and calls it (suddenly) just like fcs:

 git remote add fcs <адрес репозитория подрядчика> 

And from time to time, the master can make changes into his branch that have been made by the customer (at once, do not waste time on fetch + merge):

 [vasya@wrkst1 avn]$ git pull fcs master remote: Counting objects: 7, done. remote: Compressing objects: 100% (6/6), done. remote: Total 6 (delta 2), reused 0 (delta 0) Unpacking objects: 100% (6/6), done. From gitserver:polygon/fcs * branch master -> FETCH_HEAD Updating 4d71f77..c54c562 Fast-forward fcs-file1.txt | 0 fcs-file2.txt | 0 fcs-file3.txt | 0 3 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 fcs-file1.txt create mode 100644 fcs-file2.txt create mode 100644 fcs-file3.txt 

And on the server of the contractor the same 6 commits appear as for the customer with the same SHA-1.

Phase 5. Contractor doing some refinement

 touch avn-megafix1.txt git add avn-megafix1.txt git commit -m "avn-megafix1.txt" 

He tests, pours into his repository, informs the person responsible for integration on the part of the customer, so that he takes over the modifications.

Phase 6. The customer takes the changes to his repository.

In principle, the actions are symmetrical to step 4: the person responsible for integration at the customer connects a remote repository avn to his copy of the fcs repository:

 git remote add avn <адрес репозитория подрядчика> 

And after that it can pick up changes from the server of the contractor:

 git pull avn master 

Getting exactly the same commits, with the same SHA-1 IDs as the contractor.

Basically, that's all in general terms. Indeed, nothing complicated - the main thing is that the servers are available.

  • Some moments are specific and I did not describe them, plus working with the branches of the features is not described, in fact it means the creation of local branches under the features and merry richest in the remote gitlab. - AK

The option "transfer the backup of the database and the archive with the files" is certainly not suitable: I want to leave the entire history of commits

git is a distributed version control system. any clone (made by the git clone command) is a complete repository with a complete history. if the only method of communication is file sharing, then you can use, for example, the git bundle command. or, in extreme cases, make an archive of the contents of the repository - that is (in a non-bare repository) of the .git directory. This directory contains the whole story.

provide the possibility of making patches by contractors

  • without access to each other's repositories, the customer and the developer can exchange patches: using the git format-patch command, you can create a set of patches (one per commit), and using the git apply you can apply these patches to another clone of this repository.
  • if you still have access to the contractor’s storage using any git / ssh / http / https protocol supported by the git program, you can connect additional storages to the existing clone using the git remote command, pick up the changes with the git fetch command and merge them with the local branch git merge .

details:

  • Thanks for the links, we have a self-education day on Friday - I will try tomorrow and read about several remote repositories and drive tests. - AK