Skip to content

Suggest to use `git checkout -B` in "Check out branch" instructions

Peter Leitzen requested to merge pl-mr-collaboration into master

What does this MR do and why?

Running git checkout -b contributor/fork-branch' FETCH_HEAD (note the lowercase -b) twice fails with:

fatal: A branch named 'contributor/fork-branch' already exists.

Using git checkout -B always works and just resets the branch if it already exists:

git checkout -B contributor/fork-branch
Reset branch 'contributor/forr-branch'

According to man git-checkout:

If -B is given, <new_branch> is created if it doesn’t exist; otherwise,
it is reset. This is the transactional equivalent of

    $ git branch -f <branch> [<start point>] $ git checkout <branch>

that is to say, the branch is not reset/created unless "git checkout" is successful.

Screenshots or screen recordings

Before After
Screenshot_from_2022-09-29_11-13-49 Screenshot_from_2022-09-29_11-14-10
Screenshot_from_2022-09-29_11-15-10 Screenshot_from_2022-09-29_11-15-16

How to set up and validate locally

  1. Go to a Community contribution MR like !95107 (merged)
  2. Click on Code > Check out branch (top right corner)
  3. Click on Copy commands next to Step 1
  4. Paste these commands in your console
  5. Paste these commands in your console again

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Peter Leitzen

Merge request reports

Loading