Community
Participate
Working Groups
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.
(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
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.
Created attachment 221784 [details] TortoiseGit Switch Branch Dialog
Created attachment 221785 [details] TortoiseGit Detached Head warning
*** Bug 360163 has been marked as a duplicate of this bug. ***
Proposed fix: https://git.eclipse.org/r/16025
merged as 47cb869505e1134e196b843a68ebb6f4a19cefa0
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.