0

I have main dev branch and I want to use pipeline to merge dev into some branch via common shell script.

Pipeline snippet is below:

steps:
  - checkout: self
    clean: true
    persistCredentials: true

  - task: Bash@3
    displayName: "dev merging to source branch"
    env:
      SYSTEM_ACCESSTOKEN: $(System.AccessToken)
      BRANCH: *
    inputs:
      targetType: "inline"
      script: |

        git config --global user.email "..."
        git config --global user.name "..."
        
        git remote -v

        git pull
        
        git checkout dev
        git checkout $BRANCH
        git status

        git merge $BRANCH dev 
        git status

        git push origin HEAD:origin/task/temp_branch

But I got different errors (for example like this):

HEAD is now at f7d3f878 Update auto-merge-v4.yml for Azure Pipelines
HEAD detached at origin/task/temp_branch
nothing to commit, working tree clean
Merge made by the 'ort' strategy.

...
 .../src/core/...                |  2 +-
...

 6 files changed, 28 insertions(+), 12 deletions(-)
HEAD detached from origin/task/temp_branch
nothing to commit, working tree clean
To https://dev.azure.com/quantori/org-skill-matrix-service/_git/org-skill-matrix-service-v4
 ! [rejected]          HEAD -> origin/task/temp_branch (fetch first)
error: failed to push some refs to 'https://dev.azure.com/quantori/org-skill-matrix-service/_git/org-skill-matrix-service-v4'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

What am I doing in wrong way? In my view everything is logical and right. Are there any best practices to do such a tasks?

  • 2
    The error you received means the branch you are pushing to isn't up to date with the remote. In this case it appears to be `origin/task/temp_branch`. If you don't care about what is already on the server for that branch, consider using `push -f`. Does this answer your question? [Updates were rejected because the remote contains work that you do not have locally](https://stackoverflow.com/questions/24357108/updates-were-rejected-because-the-remote-contains-work-that-you-do-not-have-loca) – TTT Jun 23 '22 at 14:25
  • btw - for automatic merge you can use the following extension (with "auto complete" feature): https://marketplace.visualstudio.com/items?itemName=ShaykiAbramczyk.CreatePullRequest – Shayki Abramczyk Jun 23 '22 at 14:40
  • When you run `git merge $BRANCH dev` you should see `Merge made by the 'octopus' strategy`, but you actually see `Merge made by the 'ort' strategy`. This in turn implies that `$BRANCH` isn't set. I'm not sure why that is the case, but env settings are specific to Azure pipelines here. – torek Jun 25 '22 at 00:23
  • Meanwhile, you almost certainly *don't* want `git merge $BRANCH dev` if you *do* get `BRANCH` set, because unless you know what an octopus merge *is*, you don't want one, and if you *had* checked out `$BRANCH` there would be no point in using it as an argument to `git merge`. So once you straighten out your use of environment variables per whatever Azure provides, you'll need to revisit your commands. – torek Jun 25 '22 at 00:26

0 Answers0