Detached head state in closed development environment

270 Views Asked by At

A similar question has been asked already, however it does not provide the solution for my situation. My origin/develop branch is in a closed environment (azure devops) and can only be changed via a pull request. Also it is in detached head state. Following the solution of @Chris Johnsen, I get the following when I'm in the origin/develop branch in my local repo (note that I can not make changes here, only view the state of things. changes must be done via PR in devops):

SHA-1 info

commit 78f7cbda2d853abaa85a2094a683e2ca3a9dad24 (HEAD, origin/develop, origin/HEAD, feature/temp, develop)
commit 94007d2278f70e7e7b59de6a4735daf7806e5032 (origin)

$ git symbolic-ref HEAD
fatal: ref HEAD is not a symbolic ref

$ git rev-parse HEAD
78f7cbda2d853abaa85a2094a683e2ca3a9dad24

Then create a temporary branch with a reattached HEAD that points to the commit currently pointed to by the detached HEAD

git checkout -b feature/temp 

where

 git diff origin/develop feature/temp 

yield no differences

So far so good, but here is where things get tricky.

$ git branch -f origin/develop feature/temp
fatal: cannot lock ref 'refs/heads/origin/develop': 'refs/heads/origin' exists; cannot create 'refs/heads/origin/develop'

This does not work because origin/develop is a closed azure devops environment and only accessible via pull requests. How do I reconcile the detached head state in my origin/develop branch via a pull request?

PS: I actually want to go back to the origin state in origin/devops which is the following SHA-1:commit 94007d2278f70e7e7b59de6a4735daf7806e5032 (origin)

I assumed I first had to first go back to the HEAD state via PR and then to this state with a second PR, but if there is a way to do it in one PR then I would be forever thankful

1

There are 1 best solutions below

2
matt On

This has nothing to do with azure devops, detached head, PR, or any of the other terms you tossed around. What you're doing is perfectly normal and correct: you just want to start a new branch at a particular commit. The only issue is your use of the Git "language": Your command is backwards.

git branch -f origin/develop feature/temp

What you mean is exactly the opposite:

git branch feature/temp origin/develop

But since you are already at origin/develop, you don't need to specify it anyway. Just say

git switch -c feature/temp