Can any one help me how to run git command in my build pipeline. I want to merge my dev branch in to staging branch before start build the solution to deployment. I have add command line task and run git commands but its not giving any result from GIT

- 616
- 1
- 7
- 19
-
Not get your latest information, are the answers helpful for you? Or if you have any concern, feel free to share it here. If the answer is helpful, please [mark it as answer](https://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work/5235#5235). – Kevin Lu-MSFT Jun 19 '20 at 09:02
4 Answers
This the way how I'm accomplishing interaction with the git repo directly in the yaml pipeline bash command
cd $(Agent.BuildDirectory)/s
# Update Git User
git config --global user.email $(GITHUB_EMAIL)
git config --global user.name $(GITHUB_NAME)
# Switch to clone from branch
git checkout -b $(FROM_BRANCH) origin/$(FROM_BRANCH)
# do your code manipulations here then push them upstream
git push origin -f $(TO_BRANCH)

- 170
- 8
-
this is what i m expecting. will try this and let you know with update.thanks – CodeMind Jun 15 '20 at 08:04
I want to merge my dev branch in to staging branch
You could try to use git merge
command to merge.
Here is an example:
git remote add Reponame https://PAT@dev.azure.com/orgNAME/project name/_git/Reponame
git checkout -b staging
git pull
git merge remotes/origin/dev
git push Reponame staging -f
You could directly use this command in the Command Line Task
.
Then the Dev branch
will merge to the Staging branch
.
You could get the following build log.
Hope this helps.

- 20,786
- 3
- 19
- 28
It's been a while since the question was asked. But I'd like to introduce an alternative way (from an example in the official documentation) for those seeking to run code before git checkout in a pipeline:
steps:
- script: |
git config --global --add filter.lfs.required true
displayName: Configure LFS for use with submodules
- checkout: self

- 2,134
- 2
- 18
- 13
Normally you have two pipelines one for the PR, to check that all your changes compile without error, And then the CI build that compile and publish the artifact or make the deploy if you don't have releases.
So the CI build only is triggered when the Master branch change. So you don't have to make the merge whit a task, you have to make the merge and then launch the build pipeline.

- 585
- 1
- 3
- 12
-
First carefully read my question.no issue with building the solution and publishing artifacts. all working fine.its not the problem for me. all i need is to create one task for merge two branch (run git command). once release done i need to update target branch – CodeMind Jun 15 '20 at 08:03
-
Oh, sorry man, if the other user's answer doesn't work for you I think you can try it with the Powershell task like in the answer of this questions, https://stackoverflow.com/questions/55833316/cannot-clone-git-repository-in-command-line-script-task-in-azure-devops-pipeline – Nacho Martínez-Aedo Jun 15 '20 at 08:58