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
.
Force a Checkout You can pass the -f or --force option with the git checkout command to force Git to switch branches, even if you have un-staged changes (in other words, the index of the working tree differs from HEAD ). Basically, it can be used to throw away local changes.
you can do git checkout -m <branch-name> to merge conflicts and checkout to the branch and resolve conflicts yourself, or git checkout -f <branch-name> to ignore changes.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With