This article introduces three common application scenarios about git branches in work
Article directory
-
-
- Scenario 1: There is already a local branch, and the remote needs to create a corresponding branch with the same name
- Scenario 2: There is already a remote branch, and a new corresponding branch with the same name needs to be created locally
- Scenario 3: There are local branches and remote branches with different names, let them track
-
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
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
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
update commit
The third option is not recommended, generally the local and remote branch names correspond