Bug 341679 - EGit allows check-out of remote branch but doesn't create local branch to work with
Summary: EGit allows check-out of remote branch but doesn't create local branch to wor...
Status: RESOLVED FIXED
Alias: None
Product: EGit
Classification: Technology
Component: UI (show other bugs)
Version: 0.11   Edit
Hardware: PC Linux
: P3 enhancement with 2 votes (vote)
Target Milestone: 3.1   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords: noteworthy
: 360163 (view as bug list)
Depends on:
Blocks:
 
Reported: 2011-04-01 17:39 EDT by Jeff Johnston CLA
Modified: 2019-09-26 04:51 EDT (History)
5 users (show)

See Also:


Attachments
TortoiseGit Switch Branch Dialog (9.74 KB, image/png)
2012-10-02 12:13 EDT, Kevin Sheedy CLA
no flags Details
TortoiseGit Detached Head warning (20.00 KB, image/png)
2012-10-02 12:13 EDT, Kevin Sheedy CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jeff Johnston CLA 2011-04-01 17:39:14 EDT
Team->Branch... allows one to switch to a remote branch, but there doesn't seem to be a way to do the equivalent of creating a local branch that points to this remote branch.

I was in my local master branch and wanted to work on stable-0.7, a branch of the project for 0.7.  Using Team->Branch... I checked out the remote/stable-0.7 branch.

After switching to the remote branch, I was allowed to make commits, but when I switched back to my local master branch, there was no way to get back to my changes in 0.7.  If I checked out remote/stable-0.7 branch again, I got the remote contents.

This is very confusing and I would recommend that if I go to check out a remote branch that I be offered the opportunity to create a local branch with the appropriate name to use for code changes.
Comment 1 Matthias Sohn CLA 2011-04-21 19:48:18 EDT
(In reply to comment #0)
> Team->Branch... allows one to switch to a remote branch, but there doesn't seem
> to be a way to do the equivalent of creating a local branch that points to this
> remote branch.

Select the remote tracking branch in Git Repositories View and click "Create Branch..."
This will create a local branch which will track the remote tracking branch. 
I.e. when running pull this will fetch new data and merge (or rebase depending
on branch configuration) to the local branch.

> I was in my local master branch and wanted to work on stable-0.7, a branch of
> the project for 0.7.  Using Team->Branch... I checked out the remote/stable-0.7
> branch.
> 
> After switching to the remote branch, I was allowed to make commits, but when I
> switched back to my local master branch, there was no way to get back to my
> changes in 0.7.  If I checked out remote/stable-0.7 branch again, I got the
> remote contents.

If you checkout a remote tracking branch you have detached HEAD (decorator shows 
commit SHA1 and no longer branch name). It's still possible to create commits in 
this state but these are not tracked by any branch (that's why this is called detached). 
Native Git behaves exactly in the same way [1].
 
> This is very confusing and I would recommend that if I go to check out a remote
> branch that I be offered the opportunity to create a local branch with the
> appropriate name to use for code changes.

That's a good idea, we could add a warning dialog for beginners: 

"You are about to checkout a remote tracking branch, this would yield a detached HEAD. Maybe you meant to create a new local branch based on this remote tracking branch"

This dialog should also have a preference to disable it.

Changing this to an enhancement as this is no bug.

[1] section DETACHED HEAD in http://www.kernel.org/pub/software/scm/git/docs/git-checkout.html
Comment 2 Kevin Sheedy CLA 2012-10-02 12:12:40 EDT
Agreed, if the user tries to checkout a remote branch, they should be given the option to create the local branch instead.

Here's a very common user story:

1) My colleague creates a branch and pushes it to a central repo
2) I pull from this repo and see his new branch
3) I switch to this branch and make some commits
4) I push my changes back to the central repo

I wouldn't expect to have to explicitly Create a Branch myself as my collegue has already done the create. I'd expect to just do a "Switch" branch.

TortoiseGit handles this very nicely. When the user tries to switch to this new (remote) Branch, the user is shown a dialog with a checkbox to create the local branch and switch to it instead. It is checked by default. If the user un-checks the checkbox, they can switch to the remote branch and they are given a warning about being in a 'detached HEAD' state.
Comment 3 Kevin Sheedy CLA 2012-10-02 12:13:16 EDT
Created attachment 221784 [details]
TortoiseGit Switch Branch Dialog
Comment 4 Kevin Sheedy CLA 2012-10-02 12:13:42 EDT
Created attachment 221785 [details]
TortoiseGit Detached Head warning
Comment 5 Robin Stocker CLA 2013-04-18 04:30:23 EDT
*** Bug 360163 has been marked as a duplicate of this bug. ***
Comment 6 Robin Stocker CLA 2013-09-01 15:11:34 EDT
Proposed fix: https://git.eclipse.org/r/16025
Comment 7 Matthias Sohn CLA 2013-09-19 06:46:52 EDT
merged as 47cb869505e1134e196b843a68ebb6f4a19cefa0
Comment 8 Uladzimir Simankou CLA 2019-09-26 04:51:20 EDT
Have met this issue recently on 

Ubuntu 18.04

Eclipse IDE for C/C++ Developers
Version: Oxygen.3a Release (4.7.3a)

EGit v5.2.0.201812061821-r 

The solution was to check

Window->Preferences->Team->Git->Confirmation And Warnings->Detached HEAD and checkout of remote-tracking branch

It was unchecked in my case.