Skip to content

Instantly share code, notes, and snippets.

@Fazzani
Forked from joncloud/pr.md
Created April 10, 2021 07:35
Show Gist options
  • Save Fazzani/86879a5b11f6b4f6a5bc42b9cbb4839d to your computer and use it in GitHub Desktop.
Save Fazzani/86879a5b11f6b4f6a5bc42b9cbb4839d to your computer and use it in GitHub Desktop.
Checkout vsts pull requests locally

Forked from piscisaureus

Locate the section for your vsts remote in the .git/config file. It looks like this:

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

Now add the line fetch = +refs/pull/*/merge:refs/remotes/origin/pull/* to this section. Obviously, change the url to match your project's URL. It ends up looking like this:

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

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/1009/merge -> origin/pull/1009
...

To check out a particular pull request:

$ git checkout pull/1009
Branch pull/1009 set up to track remote branch pull/1009 from origin.
Switched to a new branch 'pull/1009'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment