-1

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

Eeuwigestudent1
  • 161
  • 1
  • 2
  • 13
  • What you need to realize is that *your* `origin/develop` is a *reflection* of sorts. Your Git software calls up other Git software. You have a repository. *They* have a *different repository* (both repositories are "clones", but they're not 100% identical). **They have a `develop`.** Your Git software sees *their* develop, copies commits to your repository if/as needed, and creates-or-updates *your* `origin/develop` based on the hash ID they have in their `develop`. – torek Jun 25 '22 at 10:20
  • Any changes you make to *your* `origin/develop`, or even your own `develop`, don't affect *their* `develop`. They're not you! If you want them to change *their own* `develop`, you have to *ask them to do that*. You can't *make* them do that if they refuse, although you have two flavors of ask: a polite "please" and a commanding "do it!". – torek Jun 25 '22 at 10:21
  • In all cases, whether or not you get them to change *their* `develop` *hash ID*, your `origin/develop` is not a *branch* name. It's a *remote-tracking name*. When you use it, you'll get into "detached HEAD" mode. In Git, "attached HEAD" mode is only for (your) *branch* names. If you want to create a branch name, do that, then use `git switch` to switch to it; or use `git switch -c` to create it and switch to it all in one go. – torek Jun 25 '22 at 10:24
  • Once you have a *branch* named `develop` in *your* repository, you can work with it in the usual way. Then you can easily make the kind of requests to them that you might want to use to ask or command them to change *their* `develop` to match: that's `git push origin develop` (polite ask) or `git push --force origin develop` (forceful command). Be careful with `--force`, as always, since if they *do* allow it, you have great power and therefore must take great responsibility. – torek Jun 25 '22 at 10:26

1 Answers1

1

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 
matt
  • 515,959
  • 87
  • 875
  • 1,141
  • With those command the origin/develop branch stays in detached head state. With your second query, feature/temp now tracks origin/develop. The git history is the same as well. When you say I do not need a PR, I'm a bit lost since I cannot change anything in origin/develop without it. – Eeuwigestudent1 Jun 24 '22 at 10:39
  • I don't know how to respond since everything you're saying represents a misconception. I work this way all the time. Just do what I said and all will be well. (If you have a bad tracking configuration you can suppress it with `--no-track`.) – matt Jun 24 '22 at 10:45