Skip to content

Instantly share code, notes, and snippets.

@manualbashing
Forked from joncloud/pr.md
Last active May 12, 2024 15:04
Show Gist options
  • Star 15 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save manualbashing/524492e571f3cdbf0a007e54f000e1c2 to your computer and use it in GitHub Desktop.
Save manualbashing/524492e571f3cdbf0a007e54f000e1c2 to your computer and use it in GitHub Desktop.
Checkout Azure DevOps Pull Requests locally

Forked from piscisaureus

Fetch and checkout one specific pull request

To identify one particular pull request, find the pull request number on the Azure DevOps site:

image

Then fetch and checkout the pull request in a local branch named pull/137

git fetch origin pull/137/merge:pull/137
git checkout pull/137

Always fetch all pull requests for one repository

Now add the line fetch = +refs/pull/*/merge:refs/remotes/origin/pull/* to your local .git/config file. It looks like this:

git config --add remote.origin.fetch "+refs/pull/*/merge:refs/remotes/origin/pull/*"

Your local .git/config file looks now like this:

[remote "origin"]
	url = ssh://my-vsts@my-vsts.visualstudio.com:22/DefaultCollection/Project-Name/_git/Repo-Name
	fetch = +refs/pull/*/merge:refs/remotes/origin/pull/*
	fetch = +refs/heads/*:refs/remotes/origin/*

Now fetch all the pull requests:

$ git fetch origin
From ssh://my-vsts@my-vsts.visualstudio.com:22/DefaultCollection/Project-Name/_git/Repo-Name
 * [new ref]         refs/pull/1000/merge -> origin/pull/1000
 * [new ref]         refs/pull/1002/merge -> origin/pull/1002
 * [new ref]         refs/pull/1004/merge -> origin/pull/1004
 * [new ref]         refs/pull/137/merge -> origin/pull/137

to checkout a pull request into a local branch named pull/137 use:

$ git checkout pull/137
Branch pull/137 set up to track remote branch pull/137 from origin.
Switched to a new branch 'pull/137'

Always fetch all pull requests for all repositories

git config --global --add remote.origin.fetch "+refs/pull/*/head:refs/remotes/origin/pr/*"

References

published: true
@VisualFinesse
Copy link

Exactly what I needed thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment