Git checkout -b, branch already exists

gitgithub

When I'm merging two branches and they can't be merged automatically Github provides these instructions:

Step 1: From your project repository, bring in the changes and test.

git fetch origin
git checkout -b master origin/master
git merge develop

Step 2: Merge the changes and update on GitHub.

git checkout develop
git merge --no-ff master
git push origin develop

But, in this case, the branch master already exists locally, and the line git checkout -b master origin/master returns this message:

git checkout -b master origin/master
fatal: A branch named 'master' already exists.

Is the correct thing to do in this case to replace that line with git checkout master? I've wondered this for a while, bit worried about what git checkout master might do as opposed to with -b.

Best Answer

If master doesn't exist, then after this line

git checkout -b master origin/master

master will be a branch pointing to the same commit as origin/master.

If you already have a master branch, it might be out of date with origin/master, so simply writing

git checkout master

isn't quite enough. You'll also want to run

git merge origin/master

afterward to bring master up to date (typically this will just be a fast forward).