tris
tris

Reputation: 1831

refs/pull/*/head -> origin/pr/* appearing on a git pull

Since about a month ago, every time I issue a 'git pull', I end up with a bunch of remotes/origin/pr/* branches on my 'git branch -a', which map directly to the number of pull requests having ever been opened in this repo. Doing a 'git remote prune origin' cleans them up.

Before Pull :

C:\experimental [develop]> git branch -a
* develop
  feature/291
  master
  remotes/origin/HEAD -> origin/master

Pull :

C:\experimental [develop]> git pull
From https://github.com/.../experimental
 * [new ref]         refs/pull/1/head -> origin/pr/1
 * [new ref]         refs/pull/10/head -> origin/pr/10
 * [new ref]         refs/pull/100/head -> origin/pr/100
 * [new ref]         refs/pull/101/head -> origin/pr/101
 * [new ref]         refs/pull/102/head -> origin/pr/102
 * [new ref]         refs/pull/103/head -> origin/pr/103
...
 * [new ref]         refs/pull/103/head -> origin/pr/382

After Pull:

C:\experimental [develop]> git branch -a
* develop
  feature/291
  master
  remotes/origin/HEAD -> origin/master
  remotes/origin/pr/1
  remotes/origin/pr/10
  remotes/origin/pr/100
  remotes/origin/pr/101
  remotes/origin/pr/102
  remotes/origin/pr/103
...
  remotes/origin/pr/382

Cleanup :

C:\experimental [develop]> git remote prune origin
Pruning origin
URL: https://github.com/.../experimental.git
 * [pruned] origin/pr/1
 * [pruned] origin/pr/10
 * [pruned] origin/pr/100
 * [pruned] origin/pr/101
 * [pruned] origin/pr/102
 * [pruned] origin/pr/103
...
 * [pruned] origin/pr/382

After Cleanup :

C:\experimental [develop]> git branch -a
* develop
  feature/291
  master
  remotes/origin/HEAD -> origin/master

How do I stop the initial 'git pull' from pulling them down ? It only started to happen about a month and a bit ago.

Thanks.

Upvotes: 4

Views: 5944

Answers (2)

dahlbyk
dahlbyk

Reputation: 77620

Somehow it was added to my system level git config.

This was probably GitHub for Windows (or Mac?), which provides an enhanced --system config, as you discovered, including:

[remote "origin"]
    fetch = +refs/heads/*:refs/remotes/origin/*
    fetch = +refs/pull/*/head:refs/remotes/origin/pr/*

(You can confirm with git config --get-all remote.origin.fetch.)

If you don't find the origin/pr refs useful, removing the refs/pull line will indeed do the trick. Personally I find them useful, so the prune behavior you discovered was frustrating:

In older versions of Git, if the refs/pull line came after the refs/heads line a remote prune would strip out the origin/pr refs; swapping the lines let the origin/pr refs survive.

That bug was fixed in Git 1.9.2:

 * "git fetch --prune", when the right-hand-side of multiple fetch
   refspecs overlap (e.g. storing "refs/heads/*" to
   "refs/remotes/origin/*", while storing "refs/frotz/*" to
   "refs/remotes/origin/fr/*"), aggressively thought that lack of
   "refs/heads/fr/otz" on the origin site meant we should remove
   "refs/remotes/origin/fr/otz" from us, without checking their
   "refs/frotz/otz" first.

   Note that such a configuration is inherently unsafe (think what
   should happen when "refs/heads/fr/otz" does appear on the origin
   site), but that is not a reason not to be extra careful.

Upvotes: 1

Slaven Rezic
Slaven Rezic

Reputation: 4581

Probably you followed the suggestion how to check out pull requests locally (see https://help.github.com/articles/checking-out-pull-requests-locally ). To get rid of this, just remove the line

fetch = +refs/pull/*/head:refs/remotes/origin/pr/*

from your .git/config.

Upvotes: 9

Related Questions