When we use git for development, we often encounter the situation that we need to switch the remote branch and submit it to the remote specified branch. Now, record the operation steps.
View all remote branches
$ git branch -a
Git branch does not have parameters. It lists the local existing branches and marks them with * in front of the current branch. With the – a parameter, you can view the list of all branches, including local and remote branches. Remote branches are generally marked in red font
* dev master remotes/origin/HEAD -> origin/master remotes/origin/master remotes/origin/release/caigou_v1.0
Create a new branch and switch to the specified branch
git checkout -b dev origin/release/caigou_v1.0
git checkout -bLocal branch name origin / remote branch name
This command can pull the specified branch in the remote git repository to the local, so that a new dev branch is created locally, and the specified remote branch release / caigou_ V1.0.
Switched to a new branch 'dev' Branch 'dev' set up to track remote branch 'release/caigou_v1.0' from 'origin'.
View local branches and tracked branches
$ git branch -vv
The GIT branch – VV command can display all local branches. The execution results are as follows:
* dev e67e3ef [origin/release/caigou_ V1.0] supplier details page master 11160c2 [origin/master: behind 5] Merge branch 'master' of https://git.jointforce.com/scm/join/yj-stat
*Represents the current branch, [remote branch] represents the remote branch tracked by the current local branch, and the last one is the latest submitted comment.
Push local branch to remote
$ git push -u origin dev:release/caigou_v1.0
Git push < remote host name > < local branch name >: < remote branch name >
After success, it is shown as follows:
Counting objects: 8, done. Delta compression using up to 4 threads. Compressing objects: 100% (8/8), done. Writing objects: 100% (8/8), 754 bytes | 754.00 KiB/s, done. Total 8 (delta 6), reused 0 (delta 0) remote: remote: Create pull request for release/caigou_v1.0: remote: https://git.jointforce.com/projects/JOIN/repos/yj-stat/compare/commits?sourceBranch=refs/heads/release/caigou_v1.0 remote: To https://git.jointforce.com/scm/join/yj-stat.git a22ed65..e8782b2 dev -> release/caigou_v1.0 Branch 'dev' set up to track remote branch 'release/caigou_v1.0' from 'origin'.
The above command means pushing the local dev branch to a remote release / caigou_ V1.0 branch.
This article introduces the method of GIT switching to the specified remote branch. For more information about git switching to the specified remote branch, please search the previous articles of developeppaer or continue to browse the related articles below. I hope you can support developeppaer more in the future!