Git fetch Pull Requests from Azure DevOps
Git fetch Pull Requests from Azure DevOps
问题
I want to fetch, using git, the list of Pull Requests in a repository hosted in Azure DevOps.
Github has the support. We can just add this to .git/config
:
[remote "origin"]
fetch = +refs/pull/*/head:refs/remotes/origin/pr/*
But when I tried the same method for Azure DevOps, it didn't fetch anything. I also tried git-pr
from the git-extras
package.
I am guessing if they have the support, the path might be different from refs/remotes/origin/pr/
.They have a REST API endpoint to fetch pull requests, but I couldn't find anything about doing the same using git.
回答
For Azure DevOps the configuration is slightly different. You can add the following to .git/config
:
下面这个配置,只能获取Active的pull request
[remote "origin"]
fetch = +refs/pull/*/merge:refs/remotes/origin/pull/*
It is also possible to perform an ad-hoc fetch of a pull-request into a local branch without prior configuration like this:
git fetch origin refs/pull/$ID/merge:$LOCALBRANCH
Example fetch and checkout (with configuration):
$ git fetch origin -v
remote: Azure Repos
remote: Found 1 objects to send. (18 ms)
Unpacking objects: 100% (1/1), done.
From ssh.dev.azure.com:v3/aaaa/bbbb/cccc
= [up to date] main -> origin/main
= [up to date] test-branch -> origin/test-branch
* [new ref] refs/pull/1/merge -> origin/pull/1
$ git checkout pull/1
Branch 'pull/1' set up to track remote branch 'pull/1' from 'origin'.
Switched to a new branch 'pull/1'
Example ad-hoc fetch and checkout (no prior configuration):
下面这个可以拿到已经完成的pull request
$ git fetch origin refs/pull/1/merge:pull/1
remote: Azure Repos
remote: Found 1 objects to send. (53 ms)
Unpacking objects: 100% (1/1), done.
From ssh.dev.azure.com:v3/aaaa/bbbb/cccc
* [new ref] refs/pull/1/merge -> pull/1
$ git checkout pull/1
Switched to branch 'pull/1'
https://gist.github.com/manualbashing/524492e571f3cdbf0a007e54f000e1c2
Always fetch all pull requests for all repositories
git config --global --add remote.origin.fetch "+refs/pull/*/head:refs/remotes/origin/pr/*"
作者:Chuck Lu GitHub |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
2021-08-10 哈啰单车流量问题
2019-08-10 .net reflector
2017-08-10 数据库中的Convert
2017-08-10 xml Data Type Methods in sql server
2015-08-10 VS中常用的快捷键
2015-08-10 wcf中的File-less Activation
2015-08-10 什么是SysWow64