0

I am new to GIT. I have created a virtual host and setup my project locally. All the branches of the site list out including origin/sprint. I wanted to switch to origin/sprint branch and start my work. (I am not the one who created a origin/sprint branch.) So I gave git checkout origin/sprint and now it has checked out as follows. ((HEAD detached at origin/sprint))

I made some changes in that sprint branch too. But I didn't commit yet. I want to know whether it will be a problem if I commit by staying as ((HEAD detached at origin/sprint)) ?

If committing in HEAD detached is not the correct way, what are the steps should I follow as I have done some changes in that HEAD detached.

Thank you.

2
  • this post should help you out link Commented Mar 23, 2020 at 19:50
  • As eftshift0 answered, working on a detached HEAD in Git is OK. As you are a Git beginner, though, I don't recommend it: it's a little like taking the training wheels off the bicycle, or walking a tightrope without a safety net. :-) Make yourself a branch name to use.
    – torek
    Commented Mar 23, 2020 at 20:31

2 Answers 2

2

There is no problem (technically) with being on detached HEAD. You are working without a branch because you asked git to checkout a remote branch. If you haven't committed anything and you would rather create your local sprint branch from remote sprint, you can run this:

git checkout -b sprint
git branch --set-upstream-to=origin/sprint

that should do

2
  • 2
    Probably best to do the checkout without -b, so as to make sprint link to origin/sprint.
    – torek
    Commented Mar 23, 2020 at 20:21
  • 1
    (--set-upstream-to - the old --set-upstream has the arguments all weird)
    – torek
    Commented Mar 23, 2020 at 21:03
0

I made some changes in that sprint branch too

No, you didn't. You have committed into HEAD, because it is detached (it is not pointing to a branch but to a commit).

what are the steps should I follow as I have done some changes in that HEAD detached

That depends on what you are trying to do. If you wanted to work on a local copy of the origin/sprint branch, then do that: create a sprint branch (optionally tracking origin/sprint) and then check it out.

Assuming you just committed your changes on top of origin/sprint, you can fix it with:

git branch sprint
git checkout sprint

Not the answer you're looking for? Browse other questions tagged or ask your own question.