Reputation: 29
Firstly like to mention that I have tried a few things from prior questions but none of them fit my scenario.
This is the scenario:
I have a repository in GitLab and I am trying to resolve a Merge Request i.e. merging the associated branch of the MR to master. After committing and pushing all the changes to the MR branch 19-some-function
, I followed the instructions in Gitlab [4] to manually merge
which results in a detached HEAD
state.
$ git fetch origin
$ git checkout -b 19-some-function origin/19-some-function
fatal: A branch named '19-some-function' already exists.
$ git checkout origin/master
Note: switching to 'origin/master'.
You are in 'detached HEAD' state. You can look around, make experimental
[truncated]
$ git merge --no-ff 19-some-function
Merge made by the 'recursive' strategy.
package-lock.json | 55 +++++++
package.json | 1 +
src/Common/Constants.js | 2 +-
src/Common/utils.js | 23 +++
(as opposed to doing it by Gitlab MR page UI: "resolve WIP" > "Merge" by clicking the button which to be frank I am not sure what it does BHS. However must add, when I did use the UI, I did not get a detached HEAD) I am the only developer and there is no separate reviewer yet, so I do not know if Step 1 & 2 in the instructions are redundant (it attempts to create the MR branch. which makes sense for a reviewer but as a developer of the feature I already have the branch so git
throws an error, seen above therefore did not make sense to run git fetch origin
again before checkout
).
How do I resolve this detached HEAD
such that it is recorded as the merge of 19-some-function
with master
? Will question/answer (2) above help?
[4] MR branch is 19-some-function
Check out, review, and merge locally
×
Step 1. Fetch and check out the branch for this merge request
git fetch origin
git checkout -b 19-some-function origin/19-some-function
Step 2. Review the changes locally
Step 3. Merge the branch and fix any conflicts that come up
git fetch origin
git checkout origin/master
git merge --no-ff 19-some-function
Step 4. Push the result of the merge to GitLab
git push origin master
Upvotes: 0
Views: 5820
Reputation: 30222
You set yourself on detached HEAD state when you ask to checkout origin/master. You are not checking out the local branch master, so you have to be put on detached HEAD. But that is ok. You could then merge the PR branch you want and then push to origin/master if you wanted to:
git push origin HEAD:master
Upvotes: 4