Git -- "Branch operation and team collaboration

Table of contents

Git branch operations

Branch advantages

branch operation command

Git team collaboration

Collaboration within the team

Collaborate across teams


Git branch operations

In the version control process, multiple tasks are advanced at the same time. For each task, we can create a separate branch for each task. Using branches means that programmers can separate their work from the main line of development. When developing their own branches It will not affect the operation of the mainline branch. For beginners, to put it bluntly, a branch can be simply understood as a copy, and a branch is a separate copy.

Branch advantages

Simultaneously push multiple function development in parallel to improve development efficiency; in the development process of each branch, if the development of one branch fails, it will not have any impact on other branches, and the failed branch can be deleted and restarted.

branch operation command

command name effect
git branch branch name create branch
git branch -v View branch
git checkout branch name switch branch
git merge branch name Merge the specified branch into the current branch

We can view current branches and create new ones .

Creating a new branch can modify the file , and after the modification, the process of submitting the local library must be performed again.

Merge the specified branch into the current branch

Merging branches can cause conflicts because when merging branches, the two branches have two completely different sets of changes in the same file and in the same place. Git can't decide for us which one to use, we have to manually decide the new code content. (The common understanding is: as long as two branches make changes to the same file, a conflict will appear in the merge, because Git does not know which version to keep)

We first make some changes to the content of the branch to be merged

After the modification is completed, switch to the master branch for merging, and a conflict log appears, indicating that the automatic merge failed, because there is a merge code conflict in the say.txt file

Because git made changes to both branches, git doesn't know which one we want to save, so there is a merge conflict.

Next we need to manually merge. Editing say.txt directly leaves what we want to keep. :wq to save.

After saving, we also need to submit our artificially modified files to the local library again. Note: When submitting the local library again, you do not need to write the file name, otherwise an error will be reported.

Summary : The essence of creating a branch is to create one more pointer; if HEAD points to master, then we are now on the master branch; if HEAD executes hot-fix, then we are now on the hot-fix pointer.

Common command steps for branching in Git:

# List all local branches

git branch

# list all remote branches

git branch -r

# Create a new branch, but still stay in the current branch

git branch [branch-name]

# Create a new branch and switch to it

git checkout -b [branch]

# Merge the specified branch to the current branch

git merge [branch]

# delete branch

git branch -d [branch-name]

# delete remote branch

git push origin --delete [branch-name]

git branch -dr [remote/branch]

If the same file is modified during the merge, it will cause a conflict. The solution is that we can modify the conflicting file and resubmit it! Choose to keep his code or yours! The master main branch should be very stable and used to release new versions. Generally, it is not allowed to work on it. Generally, the work is done on a new branch such as dev. After the work is completed, for example, it needs to be released. After the code of the dev branch is stable, it can be merged into the main branch. Branch master up.

Branches are relatively difficult in Git. Branches are parallel universes in sci-fi movies. If the two parallel universes do not interfere with each other, it will have no effect on you now. Once the two parallel universes merge at a certain point in time, we will Some issues need to be dealt with.

Supplementary knowledge :

We can check some Git-related knowledge at the end of the gitee website, here is a brief introduction.

Git command learning in gitee, learning through games, is really delicious.

Git team collaboration

Collaboration within the team

Collaborate across teams

Guess you like

Origin blog.csdn.net/qq_53123067/article/details/126659348