问题
I have a feeling i'm using the wrong words, or misunderstanding the words i'm using, which is making searching for what I want to do difficult.
Right now I have a Git repo with 3 branches hosted on Azure Devops (very similar to Github/Gitlab/Bitbucket etc).
My current flow is to commit and push locally (using PHP Storm) and then login to Azure Devops and manually use their UI to do a pull request from my develop
branch to my staging
branch. Then I log into the server and git pull from the staging
branch.
I have three branches in total develop
, staging
and production
.
But on my local machine I only ever have develop
, the others only exist on the remote server. I just work in develop
and push to origin/develop
and then do a pull request from develop
into staging
and then production
when ready.
I figure there must be a way to write a script to do all of this at once and not have to log into Azure Devops or the server.
To summarise my question as simply as possible:
I currently have to log into Azure Devops and perform the following actions:
- Login to Azure Devops
- Click branches
- Click "New Pull Request" next to the
staging
branch - Write a commit message (actually labelled "title")
- Click "Complete"
- Click "Complete Merge"
I would like to avoid logging into Azure Devops and be able to achieve this via the command line. Is this possible?
UPDATE
I've found I can basically do what I want by logging into the server and doing:
git pull
(this will pull the latest develop even though i'm in staginggit merge origin/develop
(this will merge develop into staging locally)git push
(this will update the remote staging)
This works perfectly although the one downside is that there doesn't seem to be a way to track how far behind staging
is from develop
, something which is provided by the azure devops UI.
回答1:
There's an Azure command line client which you can use to create a pull request, but not merge one. If you want to merge it as well, you'll need to use the API as Zeitounator mentions.
Depending on what you want to do, you may be able to use the azure repos pr update
command with --auto-complete
to make it merge automatically when you're happy with it as a workaround.
回答2:
Actually there are multiple ways to create a Pull request in Azure DevOps. Such as:From the Pull Requests page on the web,Team Explorer in Visual Studio, The Development section in a linked work item.
What you are looking for is creating pull request from Git Bash into Azure DevOps.
We could expand the Git aliases with VSTS CLI commands to achieve it.
There is VSTS CLI interface that we could configure to use git aliases including creating pull requests.
For the details, you can check this document:
Visual Studio and Azure DevOps Git: Extend the git command line with server commands–Part 2
Besides, you could also create a PowerShell script to streamline the process. Basically what you need to do is:
- Get the Azure DevOps access token
Pass the token to the PowerShell and let it run the setup steps.
You can check out the details here
Git Hub Repo
回答3:
I've found I can basically do what I want by logging into the server and doing:
git pull
(this will pull the latest develop even though i'm in staging
git merge origin/develop -m "My commit message"
(this will merge develop into staging locally)
git push
(this will update the remote staging)
You need to have develop locally as well for this to work.
来源:https://stackoverflow.com/questions/59958518/how-to-do-a-git-pull-request-on-remote-branches-via-the-command-line