Home > Development Tools > git > How to develop secondary development based on gitlab project

How to develop secondary development based on gitlab project

王林
Release: 2023-05-17 15:39:09
Original
1798 people have browsed it

With the rise of open source projects, more and more software engineers are attracted to join the open source community and contribute to open source projects. Among them, GitLab, an open source project based on Git warehouse, is very popular. It not only provides free code hosting services, but also provides a variety of powerful collaboration tools, allowing developers to collaborate in teams more conveniently.

However, during the code development process, sometimes there are some specific requirements. If you modify the GitLab source code directly, it may make future updates troublesome. Therefore, secondary development is extremely necessary at this time. This article will introduce how to conduct secondary development based on GitLab projects from the following aspects.

  1. Clone GitLab source code

First, you need to obtain the source code from GitLab’s official website. Here I chose gitlab-ce. After installing Git, enter the following command in the terminal:

git clone https://gitlab.com/gitlab-org/gitlab-ce.git
Copy after login

This command will download the source code of the entire GitLab project to the local, and the file will be displayed in the local warehouse in the form of the root directory of gitlab-ce.

  1. Modify GitLab code

Now, we can find the source code of GitLab in the local repository. However, we cannot modify the source code directly on the master branch, because this will make our future updates very troublesome. Therefore, we need to create a dedicated development branch.

Enter the GitLab root directory in the terminal:

cd gitlab-ce/
Copy after login

Then create a new branch:

git checkout -b my-feature-branch
Copy after login

Here we take creating a new function branch as an example, you can also Create other types of branches as needed.

Now, you can modify the code in the my-feature-branch branch. After the modification is completed, use the following command to view the modified files:

git status
Copy after login

If you only modified one file, you can use the following command to submit:

git commit -m "feat: 修改XXX文件"
Copy after login
  1. Synchronize GitLab Official code

Since we have been developing locally after creating a new branch, during this process, we may encounter situations where the GitLab official team updates the code. If we want to merge these officially updated codes into our branch, we can use the following command:

First enter the master branch:

git checkout master
Copy after login

Then pull the latest official code:

git pull origin master
Copy after login

Then return to our development branch:

git checkout my-feature-branch
Copy after login

In this way, our branch will be synchronized with the latest code. What needs to be noted here is that if two branches only modify different parts of the same file, Git will automatically merge the code for us. If two branches modify the same place, we need to manually handle the code conflict.

  1. Submit code

After we are sure that all modified code has been completed, we can use the following command to submit the code:

git push origin my-feature-branch
Copy after login

This command Our newly created branch will be updated to the GitLab server. Then, we need to submit a merge request to the official GitLab team to let them review whether our code meets their standards and merge it into the mainline branch.

  1. Deploy the secondary development code to the production environment

Once your code is merged by the official team, we still need to deploy it to the production environment. Usually, we need to pull the latest code locally, and then use the following command to deploy it to the server:

bundle exec rake gitlab:backup:create RAILS_ENV=production
sudo gitlab-ctl stop
sudo gitlab-ctl start
Copy after login

The above command is used to back up the existing GitLab data, stop the deployed GitLab service, and then start new code. Of course, what is mentioned here is just an example, and there may be other things that need attention during the actual deployment process.

Summary:

I hope that the introduction of this article can help developers better understand the secondary development process of GitLab. It should be noted that due to different technical backgrounds and differences in code quality, each developer's GitLab secondary development process may be different. Therefore, in the actual development process, it needs to be handled flexibly according to specific problems to achieve better results.

The above is the detailed content of How to develop secondary development based on gitlab project. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template