0

I am trying to merge a merge request (Gitlab) from command line.

After working on a dummy repository, I came to know that if I have the permission to merge a merge request, I can merge them directly through command line.

I started by cloning the upstream repository in my local system. After that, I made a change in my forked repository and created a merge request for the same.

While manually trying to merge the request from command line using this approach, I am getting an extra commit which is a merge commit(--no-ff).

git fetch <Fork_Repo_URL> <Fork_Repo_Branch>
git checkout -b <Branch_Name> FETCH_HEAD

git fetch origin
git checkout origin/master
git merge --no-ff <Remote_Name>-<Branch_Name>

git push origin master   

Note: The above commands are used from the cloned upstream repository.

Now, I want to do the same without cloning the upstream repository and rather by just adding an upstream remote to my forked repository.

I followed all the steps mentioned in gitlab docs for merging the request manually, but to my surprise, I am unable to see any merge commit, although the merge request is merged after using those commands.

git remote add central <Central_Repo_URL>

git fetch origin master
git checkout -b my_master FETCH_HEAD

git fetch central
git checkout central/master
git merge --no-ff my_master-master

git push central master

So, is there any way to merge a merge request by configuring a remote in forked repository(I have permission), and generate a merge commit as well?

I tried this way as well.

git fetch central
git checkout central/master
git merge --no-ff origin/master

git push central master

I have also tried commit amend, rebase.

  • I am no sure, but I think that this is the same question as your previous question: https://stackoverflow.com/questions/58889904/gitlab-merge-a-merge-request-from-command-line-not-generating-any-commitno-fast – Ahmed HENTETI Nov 16 '19 at 13:27
  • Ya sorry but in the previous question, I told about origin in upstream repo. I also though to change the previous question, but it is little bit different – Sourodeep Chatterjee Nov 16 '19 at 14:04
  • If I got my answer for this one, I will delete the previous one – Sourodeep Chatterjee Nov 16 '19 at 14:05
  • there is no problem :) By the way, I am trying to help you in the other question/thread ;) – Ahmed HENTETI Nov 16 '19 at 14:08
  • See my long answer to your previous question. – torek Nov 16 '19 at 21:26
  • @torek actually by following all the steps I have written in my question working perfectly whenever I am setting up a clone of the Upstream Repository, without setting any remote as upstream or central inside of my forked repository. But inside of my forked remote(central), this commands not generating any merge commit. But in the previous case, it is perfectly creating an extra commit. – Sourodeep Chatterjee Nov 16 '19 at 23:49
  • Note that any time you `git checkout` a *remote-tracking* name, Git will tell you that you have entered **detached HEAD** mode. All commits you make in this mode **are lost** when you *exit* this mode. **None** of them are pushed by `git push master`. – torek Nov 17 '19 at 00:23
  • So then how can I get them, get that merge commit as well? – Sourodeep Chatterjee Nov 17 '19 at 00:27
  • I think that's the problem you have spotted – Sourodeep Chatterjee Nov 17 '19 at 00:28

1 Answers1

0

I have found the solution from torek's comment above. Actually by doing

git checkout central/master

I am going to a detached HEAD, all commits in this mode are lost when I exit the node.

So the best solution should be to create a local branch which can track that upstream remote named central/master.(Please ignore my branch name)

git checkout -b centralMaster central/master

Now after doing all the above steps, we can easily solve this issue, and a no fast forward merge commit as well.

git checkout -b centralMaster central/master
git fetch central
git fetch origin
git merge origin/falcondev --no-ff -m "<Message>"
git push central centralMaster:master

Now all the above problems can be easily solved.

Please comment if I had made any mistake on these steps.