1

I'm trying to switch another branch but I keep staying on a detached head or no branch.

What I tried:

Switch/Checkout:

enter image description here

Getting:

enter image description here

But if I want to commit, I'm still on no branch:

enter image description here

And if I try to pull this branch instead:

enter image description here

I'm getting:

enter image description here

And I'm still on no branch...

How can I actually go back to the portalGraphs branch?

shinzou
  • 5,850
  • 10
  • 60
  • 124

3 Answers3

7

You tried to directly checkout a remote tracked branch. In the git philosophy this is not possible and git checks out a so-called "detached HEAD", i.e., you are not an a branch but the revision will be your HEAD (cf. Why does Git tell me "Not currently on any branch" after I run "git checkout origin/<branch>"?).

When you opened the switch/checkout dialog and you selected the remote branch, the "Create new branch" checkbox was automatically selected. This would create a local branch on the version of the remote branch. See

A quick way to fix this is to go to the switch/checkout dialog and select a local branch, such as master OR select "new branch" on the commit dialog.

MrTux
  • 32,350
  • 30
  • 109
  • 146
0

I haven't used those lousy GUI's for git.

The problem you're facing is the detached head. What you need to do is to checkout the branch. In your case checkout the master.

git checkout master 

or below command this will checkout the former branch you checked out.

git checkout - 

Detached head means you are no longer on a branch, you have checked out a single commit in the history.

After checking out the branch then you can switch to your branch.

danglingpointer
  • 4,708
  • 3
  • 24
  • 42
  • The problem was that I didn't have `portalGraphs` branch locally, so when switching to it I should have created "a new branch" for it. Git is so unnecessarily complicated, it's surprising it's so popular. PS: tortoiseGit is very close to the git CLI. – shinzou Jun 05 '17 at 08:19
  • 1
    @kuhaku - there is nothing "unnecessary" about the distinction between remote branches and local branches. It's popular because it's very powerful and very reliable. It seems "complicated" because you try to treat it like some other source control system you learned first. It is a different tool and if you want to use it effectively (and get the benefits out of those so-called "unnecessarily complicated" features) you have to learn its fundamentals. – Mark Adelsberger Jun 05 '17 at 13:42
  • I didn't say that specific thing is unnecessary. Please, even something simple as canceling a pushed commit is either hard or impossible and even destructive (reset hard, push forced, wtf?), you really think something so simple should be so complicated? Also, I doubt you and most of git users use even half of its functionality. that's why it's unnecessarily complicated, you don't really need all of these functions. @MarkAdelsberger – shinzou Jun 05 '17 at 16:59
  • 1
    @kuhaku - You complained about a specific thing you don't like by saying git is unnecessarily complicated; don't be coy, it shows that you are more interested in complaining than learning. Which, incidentally, is why I won't bother pointing out the remaining ways in which your comment is incorrect. – Mark Adelsberger Jun 05 '17 at 17:27
  • oh dear. @kuhaku, it's like this when you do something new, stumble upon new things and you eventually learn from things. Regarding the `git`, believe me, that is one of the best CVS I've used so far and elegant. I worked in very ancient stuff like clearcase, that is the worst tool I ever used. Mercury, SVN bla bla.. from all these `git` is very simple to use. I presume my answer resolved the problem you faced? – danglingpointer Jun 05 '17 at 17:33
0

From the first provided screenshot, select options "Create New Branch" and "Override branch if exists". If both options are selected then you will be in the desired branch and there will be no "No Branch" issue.

Note: both options should be selected while switching.

S Kumar
  • 555
  • 7
  • 21