https://git-scm.com/book/en/v2/Git-Branching-Remote-Branches
I would like to confirm that at the end of the "Pushing" section on the above page,
(1) Execute git merge origin/serverfix after fetch
(2) Run git checkout -b serverfix origin/serverfix
Am I correct in understanding that operation (1) and (2) have the same effect after all?
CodePudding user response:
git checkout -bcreates a different branch and switches you to it.git checkout -b serverfix origin/serverfixspecifies that the new local branchserverfixshould point to the same commit as theserverfixof theoriginremote.git mergemerges changes from the specified commit into your current branch, updating your current branch.
They’re completely different. You’ll be on different branches after executing them, and may not even have the same HEAD content.
CodePudding user response:
Yes, there is a difference; no, they don't have the same effect.
As the linked document explains, git merge origin/serverfix will merge the remote branch "origin/serverfix" with whichever branch is currently checked out (the current working branch), while git checkout -b origin/serverfix will create a new local branch named "serverfix" based on the remote "origin/serverfix" and then check out the new branch.
