[Git] Three common application scenarios of git branches

This article introduces three common application scenarios about git branches in work

Scenario 1: There is already a local branch, and the remote needs to create a corresponding branch with the same name

			git push --set-upstream origin 本地分支名

Command meaning: The current branch pushes the settings to the upstream: origin remote branch name.
Function: create a remote branch with the same name, and push the local content to the remote branch
insert image description here

Scenario 2: There is already a remote branch, and a new corresponding branch with the same name needs to be created locally

Scenario: Assume that a colleague has created a branch branch_name remotely, but you do not have this branch locally. What should I do to pull the branch at this time?

			git checkout --track origin/远程分支名

Command meaning: Create a new branch with the same name locally, switch to this branch, and track to the corresponding remote branch
Command function: Create a new branch with the same name locally, switch to this branch, track to the corresponding remote branch, and pull down the content
insert image description here

possible problems

Scenario 3: There are local branches and remote branches with different names, let them track

		git branch --set-upstream-to=origin/远程分支名 本地分支名

Command meaning: local branch set upstream to: origin/remote branch name

In this case, the push should pay attention, not directly git push, it should be like the following

		git push origin head:远程分支名
		# 将本地的head指针前的内容推送到远程分支

For example: track the local test2 branch to the remote test branch
insert image description here
update commit
insert image description here

The third option is not recommended, generally the local and remote branch names correspond

Guess you like

Origin blog.csdn.net/Supreme7/article/details/126118952