Skip to content

Cannot switch branch with untracked files #7720

Closed

Description

@markp2

Description

If you have any untracked files you cannot switch branches in desktop because this new dialog appears. Previously this was not the case and you could switch branches and carry around untracked files.

Version

GitHub Desktop: 2.03
Operating system: macOS 10.14.5 (18F132)

Steps to Reproduce

Try and switch branch with untracked files.

Expected Behavior

Ignore untracked files like the previous versions and the command line.

Actual Behavior

Annoying dialog every time you switch branches.

Additional Information

Logs

Activity

  1. shiftkey commented on Jun 7, 2019

    @shiftkey
    Member

    @markp2 thanks for the feedback!

    Previously this was not the case and you could switch branches and carry around untracked files.

    This is now that second option in the list - "Bring my changes to master". If you choose that you'll complete the flow and have your changes available there.

    The context behind this new dialog is outlined in more detail in #6107, and we decided that checkout was a good point to ask the user whether they wanted to bring the changes with them, or leave them stashed with their previous branch.

  2. markp2 commented on Jun 7, 2019

    @markp2
    Author

    @shiftkey

    Thankyou, I see that now.

    The question is, even if I confirm that changes to be brought to master, when I end up in master, whether these files are considered as potentially part of the changes to be committed? Normal git workflow distinguished between files that have been added, and files that are untracked. This new desktop change merges those two sets and therefore appears to be a regression in desktop.

    Also, this is confusing new and additional step because these are not changes. Git does not track these as changes and so why is the user being asked to bring changes [which are not changes] into the new branch?

    In my view, these are not files to be considered for version control.

  3. self-assigned this
    on Jun 7, 2019
  4. added
    more-info-needed
    on Jun 7, 2019
  5. ChristophRob commented on Jun 7, 2019

    @ChristophRob

    quite unhappy with this new feature as well, switching branches is very annoying right now. Please consider to put a new configuration setting, which removes this extra dialog

  6. shiftkey commented on Jun 7, 2019

    @shiftkey
    Member

    @markp2

    This new desktop change merges those two sets and therefore appears to be a regression in desktop.

    There's a bunch of extra context here that's unchanged from previous releases, so I'll try and cover it briefly before diving into how this affects this workflow:

    • GitHub Desktop does not distinguish between untracked files and staged new files in the working directory - both of these are displayed as "New" to the user
    • While you could stage files outside the app and switch back to Desktop, those staged changes will be unstaged before committing in Desktop to ensure what you've chosen to commit in the app is what gets committed.
    • These decisions are because we don't want to overload the user with the concept of the Git index, and make the user think about staging files. We want committing to be as simple as possible.

    Git does not track these as changes and so why is the user being asked to bring changes [which are not changes] into the new branch?

    Untracked files on one branch are not guaranteed to be untracked files on another branch, so being cautious here is how Desktop approaches it. Here's the simplest demo I could think of to illustrate why we need to be aware of untracked files in the working directory:

    $ git init test-untracked-files
    Initialized empty Git repository in /Users/shiftkey/src/test/test-untracked-files/.git/
    $ cd test-untracked-files
    $ git commit -m "empty commit" --allow-empty
    [master (root-commit) 3e95812] empty commit
    $ git branch new-branch
    $ echo "some file" >> README.md
    $ git add .
    $ git commit -m "created an empty README"
    [master 2b6971e] created an empty README
     1 file changed, 1 insertion(+)
     create mode 100644 README.md
    $ git checkout new-branch
    Switched to branch 'new-branch'
    $ echo "a different file" >> README.md
    $ git status --untracked-files=all
    On branch new-branch
    Untracked files:
      (use "git add <file>..." to include in what will be committed)
    
    	README.md
    
    nothing added to commit but untracked files present (use "git add" to track)
    $ git checkout master
    error: The following untracked working tree files would be overwritten by checkout:
    	README.md
    Please move or remove them before you switch branches.
    Aborting

    With this new flow the dialog becomes really important, because it gives the user the chance to:

    • "Leave changes" - stash the untracked files with their current branch, checkout the other branch, and context switch to their other task
    • "Bring changes" - stash the changes, checkout the branch, pop the stash, resolve conflicts, continue working

    If we didn't do any work here, and instead ran git checkout we'd still need the user to intervene.

  7. removed
    more-info-needed
    on Jun 10, 2019
  8. removed their assignment
    on Jun 10, 2019
  9. shiftkey commented on Jun 10, 2019

    @shiftkey
    Member

    @markp2 I'm going to close this out, but let us know if you have any other questions about this area

  10. shiftkey commented on Jun 10, 2019

    @shiftkey
    Member

    @jmonrove thanks for that input. I want to provide some extra context from your comment in #6107 that I think is overlooked:

    You travel to release and merge feature_1 (stash dialog)
    You travel to master and merge release (stash dialog if you didn't stash)
    You travel back to feature_1 (time to unstash)

    This flow was intended to allow you to stash your changes on feature_1 (because that's where you were last working on them). Once those changes are stashed you won't be prompted again until you return to feature_1 and unstash them explicitly.

    The goal with this feature was not just to support "magic stashing", but to make it easier to manage your uncommitted changes. Previously those would always be carried around as you switch branches, and potentially interrupt you because Git is very conservative about how to handle these uncommitted changes if conflicts arise. But now you can park them on your current branch and switch to other work without needing to commit or stash them.

  11. jmonrove commented on Jun 10, 2019

    @jmonrove

    @shiftkey thanks for the reply!

    I understand, I like to have the option to keep things contained through the desktop application (I used to do it directly from the terminal before by stashing changes). I also agree that it will help to solve those situations where you cannot checkout a different branch because of conflicts, you can just have it stashed and then go there.

    Is just that the situation doesn't happen as often as just traveling with your changes ( it's happened probably 4 times in the last year), at least for me.

    In my case, the popup fix for a rare occurrence, has turned into the new normal

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions