Wizard
Wizard

Reputation: 22043

git push a detached head to a dev branch of remote

When git push to remote repo of dev branch, it report

[detached HEAD 0091d9a] 2019-10-27 14:13:10
 1 file changed, 1 deletion(-)
fatal: You are not currently on a branch.
To push the history leading to the current (detached HEAD)
state now, use

    git push origin HEAD:<name-of-remote-branch>

Review the branches

-  (press RETURN)
* (HEAD detached from be1d973)
  develop
  master

Should I run

git push origin HEAD:develop

push it the current modifications to develop branch? I'm afraid of potential damage.

Upvotes: 0

Views: 1241

Answers (2)

tmaj
tmaj

Reputation: 34947

@torek has got you covered, but I think it's worth listing a couple of other options:

  • create a branch from your HEAD: git checkout -b name/of/branch and then merge this into remote develop
  • create a branch from your head, merge this branch into your local develop and push your develop - this seems cleaner than pushing a branch directly onto develop, this workflow will also show you any merge conflicts earlier.
  • If Pull Requests are supported, then create a branch from your HEAD push this branch to the remote and create a Pull Request from this branch to develop.

Upvotes: 1

torek
torek

Reputation: 487755

The question:

Should I _____?

is fraught with danger regardless of what goes in the blank.1

The question as to whether you can do that is much simpler: yes, you can do that (git push origin HEAD:develop). What that will do is call up the other Git, send them any new commit(s) needed—such as 0091d9a—and then ask them to set their branch develop to point to this particular commit. If they think it's OK for them to set their develop, they will do so. If they think it is not OK, they will refuse this request. With luck, if they do refuse the request, they will also tell you why they think it is not OK.

If they accept, they've put the new commit(s) on their develop, and all the old commits that were already on their develop remain on their develop. That's probably pretty safe, but we don't know enough about how other people are using this other Git repository, nor about your commit(s), to answer that kind of question.


1Should I drive a car fast (where "fast" means, say, 50 to 70 mph or about 100 km/h)? Is that dangerous? What if I'm in a car on a freeway, where all the other cars are also driving fast? In that case, might it be dangerous to drive very slowly? What if I drive at 15 mph / 25 km/h in the fast lane of the freeway? What if I'm in a car in a parking lot or residential street?

Upvotes: 2

Related Questions