search

Home  >  Q&A  >  body text

How does the team deploy git correctly?

I am a student, and I am developing together with several classmates, and plan to use git

Currently, git has built a bare warehouse, and hooks can be automatically synchronized to the web project.

Since the code on the server is not a warehouse, now I want to import the code originally on another server into the bare warehouse, and then let team members pull it. How to do it? The way I came up with was to first pull the code to the local area, and then push it from the local area to the central warehouse. Due to automatic synchronization, the central warehouse will automatically synchronize the pushed code to the web project. But I personally feel there should be a better way. Please tell me?

Also, is the general git repository used for the entire project? Or part of the project? If it is the entire project, and users upload pictures, wouldn't the uploaded pictures have to be updated locally every time they are updated?

I have searched for information for a long time, but there is very little information on this aspect. Please give me a detailed explanation.

============================

Hello, our team has a problem in the project right now. Due to a bug in the project during 5.1, a classmate fixed the bug at home, but his computer did not have git installed, so he used ftp to upload it. . Now because ftp is used to upload, the central warehouse is not used, so the post-reveice of hooks is not triggered, and the post-reveice will not be pushed to the website project (a bit convoluted, I hope someone can understand), so now it is impossible to get the pull using git. The part he uploaded. So the problem now is that I need to write one more hook. Once the website project is changed (if it is uploaded by ftp), it will be pulled to the central warehouse, and then it can be obtained locally. Ensure that the central warehouse and website projects can be synchronized in both directions. Maybe our approach is not very good, but for the time being we can only do this. Of course, we hope that the master will provide a better method by the way. Thanks again

过去多啦不再A梦过去多啦不再A梦2768 days ago620

reply all(3)I'll reply

  • PHP中文网

    PHP中文网2017-05-02 09:33:53

    The description of the problem is not very clear, so I will briefly describe what I understand.

    The method of migrating code is no problem.
    Generally, the warehouse used by git is the entire project, which may contain some submodules.
    The user uploading pictures you mentioned is actually another issue. Have you synchronized the git project warehouse to the server and used it as the directory of the web project?

    If so, there will be a little problem. First of all, a better approach is that the git warehouse is only used for development. As for publishing and deploying web projects, use Jenkins and other tasks to do it. The specific process is:

    1. Project developers trigger github's webhook through operations, such as pushing code, tagging, etc.

    2. Github requests your deployment tool based on the webhook configuration and notifies your deployment tool to further perform the release action.

    3. The deployment tool pulls the latest code to the code directory, packages the web project through scripts or commands, generates a new web project directory, and publishes it to the server.
      In this case, the user's pictures are uploaded to the project directory in the server instead of the git code directory, so there is no need to worry about updating the uploaded pictures.

    In addition, there may be security issues when using a code repository to publish as a web project. If access rights are not well controlled, others may obtain the files in your git project, which may leak some information.

    reply
    0
  • 漂亮男人

    漂亮男人2017-05-02 09:33:53

    The method you mentioned is a very good method. The two remote warehouses cannot directly communicate with each other and need to be transferred.

    User images, caches, etc. must of course be ignored. Only valid codes are stored in the warehouse.

    reply
    0
  • PHPz

    PHPz2017-05-02 09:33:53

    Actually.gitthe folder contains all the information, you can copy it directly. But git has commands to do this

    $ git clone --bare my_project my_project.git
    Cloning into bare repository 'my_project.git'...
    done.

    This operation is basically the same as the following operation:

    $ cp -Rf my_project/.git my_project.git

    Then upload the obtained my_project.git to the server where the bare warehouse is located (replace the folder). The git documentation gives a very detailed introduction:
    Git-on-the-Server-Getting-Git-on-a-Server.

    As for the second question, feel free to add the entire project to git for management, including resource files, documents, etc. This will make it easier for teams to collaborate. But do not include the files generated by compilation. This is set through .gitignore. As for the issue of updating pictures, if the picture is a resource to be used in this project, then it will naturally need to be fetched. There is no problem.

    There are also teams that add the automatically generated IDE configuration under the project to the version management. If the team members all use the same IDE, they can share the settings. This is a matter of wisdom.

    ============

    Wait a minute, why "The central warehouse automatically synchronizes the push code to the web project", I think you should be referring to the running web service. The build server should have an unmodified local warehouse and actively send it to the code warehouse pull,然后根据最新的代码启动构建,根据构建出来的结果刷新Web服务或者打包。这个动作可以由hooks触发,但公共的代码仓库不应该发起push.

    reply
    0
  • Cancelreply