Search code examples
gitgit-mergegit-checkout

Is there a difference between "git merge" and "git checkout -b"?


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?


Solution

  • 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.