preface
Most developers are not unfamiliar with Git. They can use Git for team development and record the iteration history of the code. It is easy to track back when problems occur.
This article assumes that you know the basics of Git and is designed to help you use GitLab more efficiently.
The body of the
First, no matter the size of the team, the master branch is always synchronized with the code online.
Before the project starts, the team leader establishes the master branch, and other members pull down the master branch code. At this point, all members have the permission to modify the code.
Instead of creating the dev branch, the default code will be tweaked on master
Xiao Ming is a member of the team. He receives a task to add a function to the project. The function is called RUN.
git checkout -b run
Copy the code
This command will create a branch named run in the local master-based code, and the code is the same as that of master. Xiaoming can then develop in this branch. After development, run the following command:
git add <file>
git commit -m "add run"
Copy the code
This command adds the file to the staging area and then commits it to the local repository
At this point, Xiaoming found some bugs in the code, so it needs to be further modified. After modification, run the following command:
git commit -a --amend
Copy the code
This command appends files that have already been tracked to the last COMMIT
At this point, Ming has completely completed the run function. However, Ming finds that the master code has been updated, so Ming uses the following command
Git fetch origin master git rebase origin/masterCopy the code
This command pulls the remote repository code to the local directory and rebases the master’s changes before the current merge. This has the advantage of cleaning up the merge operation locally and making the change online.
When finished, Xiao Ming uses the following command:
git push origin run
Copy the code
This command pushes the local run branch to the remote repository.
After the push is completed, Xiaoming creates a merge Request on the Console of GitLab and sends a request to the leader to merge the code to the Master branch. After the leader reviews the code, the Run branch is merged to the Master branch through the console. So far Xiaoming completed the development
Ming and the rest of the team can again use the following command to synchronize the code to their own development repository:
Git fetch origin master git rebase origin/masterCopy the code
conclusion
This article only represents some suggestions of the author, so there may be some problems and flaws, welcome readers to point out and ask questions and discuss, thank you!