Home > Software engineering >  Is there a difference between "git merge" and "git checkout -b"?
Is there a difference between "git merge" and "git checkout -b"?

Time:10-18

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 -b creates a different branch and switches you to it. git checkout -b serverfix origin/serverfix specifies that the new local branch serverfix should point to the same commit as the serverfix of the origin remote.

  • git merge merges 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.

  • Related