Skip to content

Creating branch from detached HEAD branches from master #6085

Closed

Description

@jeffdgr8

Description

While in a detached HEAD state, creating a new branch results in that branch being branched from master instead of the currently checked out commit.

Version

  • GitHub Desktop:
    1.4.3
  • Operating system:
    Windows

Steps to Reproduce

  1. From terminal: git checkout <some_commit_hash>
  2. In GitHub Desktop: Branch -> New branch...
  3. Type a name.
  4. Create branch.

Expected Behavior

The newly created branch should point to <some_commit_hash>, as the dialog states You do not currently have any branch checked out (your HEAD reference is detached). As such your new branch will be based on your currently checked out commit (<some_commit_hash>).

Actual Behavior

The newly created branch points to the HEAD of master.

Additional Information

This happens on 1.4.2-linux1 from @shiftkey's fork as well.

Logs

Not applicable

Activity

  1. added
    investigation-needed
    on Nov 5, 2018
  2. self-assigned this
    on Nov 5, 2018
  3. added
    bug
    and removed
    investigation-needed
    on Nov 5, 2018
  4. shiftkey commented on Nov 5, 2018

    @shiftkey
    Member

    @jeffdgr8 thanks for the report! I've been able to reproduce this on master and I think it comes down to two things:

    • getStartPoint seems to default to using the default branch (ignoring the fact we're in a detached HEAD state)
    function getStartPoint(
      props: ICreateBranchProps,
      preferred: StartPoint
    ): StartPoint {
      // 
    }
    • createBranch uses this startPoint state to revert to using the default branch name
    let startPoint = undefined
    
    if (this.state.startPoint === StartPoint.DefaultBranch) {
      // This really shouldn't happen, we take all kinds of precautions
      // to make sure the startPoint state is valid given the current props.
      if (!this.props.defaultBranch) {
        this.setState({
          currentError: new Error('Could not determine the default branch'),
        })
        return
      }
    
      startPoint = this.props.defaultBranch.name
    }

    There's no tests around getStartPoint so I want to wrap this current behaviour in tests before I fix the underlying issue.

  5. added
    priority-3
    on Nov 5, 2018
  6. mm-gmbd commented on Nov 20, 2018

    @mm-gmbd

    I was just about to post this exact same bug report but did one last search before submitting and found it already reported. It looks like it's already been reproduced, but I'll go ahead and include the details I had filled out anyway (as the system and GH Desktop versions are different):

    Description

    Creating a new branch from a commit that is detached from HEAD works incorrectly. The dialog box says that it will create the branch from the current commit, but when I publish the branch to GitHub, it is clear that the branch is actually created from the default branch by looking at the commit history.

    Version

    • GitHub Desktop: Version 1.5.0 (MacOS)

    image

    • Operating system: Mac OS Mojave Version 10.14

    Steps to Reproduce

    1. Checkout a particular commit to where you will be detached from HEAD (easiest to do with a SHA on the command line e.g. git checkout abcdef12)
    2. Notice that GitHub desktop relays the current git status with the SHA and the message "Detached HEAD"

    image

    1. Select "New Branch" from the branch dropdown list and notice that the dialog says that the new branch will be created from the "currently checked out commit" and that it again displays the current SHA

    image

    1. Without making any changes, publish the branch to GitHub
    2. Go to GitHub and select that branch from the list of branches
    3. Notice that the history reflects the history not of the checked out commit, but of the default branch

    Expected Behavior

    I expect that the created branch would be created from the checked out commit, rather than the default branch (like it says it will in the GH Desktop dialog box).

    Actual Behavior

    The newly-created branch is actually created as a branch from the default branch.

    Additional Information

    I can accomplish this from the command line with the following steps:

    1. Checkout a particular commit to where you will be detached from HEAD (easiest to do with a SHA on the command line e.g. git checkout abcdef12)
    2. Instead of creating a new branch from GH Desktop, create it from the command line git checkout -b new-branch
    3. Go to GH Desktop and notice that it sees you're on the new-branch
    4. Publish the branch
    5. Go to GitHub and note the branch history - this matches the history of the checked out commit, rather than the history of develop

    Logs

    There are no logs saved to the location mentioned in the contributing guide ~/Library/Application Support/GitHub Desktop/logs/. If someone can point me to the location I'd be happy to provide them.

  7. shiftkey commented on Nov 20, 2018

    @shiftkey
    Member

    @mm-gmbd thanks for the extra details - please follow along with #6104 which should resolve this

  8. added this to the 1.5.1 milestone on Nov 23, 2018
  9. bangke213 commented on Nov 23, 2018

    @bangke213
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugpriority-3

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions