Needless `-b` option in `git checkout` command for MRs

Created on 20 May 2024, 6 months ago
Updated 21 May 2024, 6 months ago

Problem/Motivation

The "check out this branch" command in command help under "Show commands" on issue merge requests includes a needless command option that makes it needlessly long and harder to read. It currently takes this form:

git checkout -b '<branch>' --track <label>/'<branch>'

The -b option is actually superfluous--the command will behave identically without it:

git checkout --track <label>/'<branch>'

This is explicit in the man page for the command:

As a convenience, --track without -b implies branch creation

and:

If no -b option is given, the name of the new branch will be derived from the remote-tracking branch, by looking at the local part of the refspec configured for the corresponding remote, and then stripping the initial part up to the "*".

Steps to reproduce

Given a clone of drupal...

Currently:

    $ git checkout -b '3422977-rename-locale-batch' --track drupal-3422977/'3422977-rename-locale-batch'
    branch '3422977-rename-locale-batch' set up to track 'drupal-3422977/3422977-rename-locale-batch'.
    Switched to a new branch '3422977-rename-locale-batch'

    $ git branch -vv | grep 3422977-rename-locale-batch
    * 3422977-rename-locale-batch e5ef631e31 [drupal-3422977/3422977-rename-locale-batch] Add setup method in LocaleBulkTest.php.

Without the superfluous option:

    $ git checkout --track drupal-3422977/'3422977-rename-locale-batch'
    branch '3422977-rename-locale-batch' set up to track 'drupal-3422977/3422977-rename-locale-batch'.
    Switched to a new branch '3422977-rename-locale-batch'

    $ git branch -vv | grep 3422977-rename-locale-batch
    * 3422977-rename-locale-batch e5ef631e31 [drupal-3422977/3422977-rename-locale-batch] Add setup method in LocaleBulkTest.php.

There is no difference between the output or results.

Proposed resolution

I figure we may as well simplify the command to make it more readable and instructive.

<!--<h3 id="summary-remaining-tasks">Remaining tasks</h3>--><!--<h3 id="summary-ui-changes">User interface changes</h3>--><!--<h3 id="summary-api-changes">API changes</h3>--><!--<h3 id="summary-data-model-changes">Data model changes</h3>--><!--<h3 id="summary-release-notes">Release notes snippet</h3>-->
πŸ“Œ Task
Status

RTBC

Version

3.0

Component

User interface

Created by

πŸ‡ΊπŸ‡ΈUnited States traviscarden

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024