4

I'm stuck for a long time with this. I'm pretty sure it came from a mistake when migrating from svn.

In the server where the bare repository is located:

$ git clone /var/git/queryj.git
$ cd queryj
$ git branch -r

origin/HEAD -> origin/remotes/trunk
origin/br-0_6--ventura24-2_0-5
origin/master
origin/remotes/br-0_6--ventura24-1_0
origin/remotes/br-0_6--ventura24-1_9-stable
origin/remotes/br-0_6--ventura24-1_9-synchr
origin/remotes/br-0_6--ventura24-2_0
origin/remotes/br-0_6--ventura24-2_0-0

When cloning the repository via https, I get different results:

$ git clone https://git.acm-sl.org/queryj.git
$ cd queryj
$ git branch -r

origin/HEAD -> origin/remotes/trunk
origin/br-0_6--ventura24-2_0-5
origin/remotes/trunk
origin/ventura24-2_0-stable

Any idea how can I make the missing branches available when cloning via https? It's exported via webdav.

Peter Bratton
  • 6,024
  • 5
  • 35
  • 60
chous
  • 81
  • 4
  • After reading [this](http://stackoverflow.com/questions/4012613/how-do-i-list-and-fetch-remote-branches-after-svn-to-git-migration), the fix was simply: In the server: git clone /var/git/queryj.git for remote in $(git branch -r); do git checkout -b $remote $remote; done git push --mirror A new clone in my local machine now sees the expected remote branches. Finally. – chous May 08 '12 at 20:39
  • Possible duplicate of [Git doesn't clone all branches on subsequent clones?](http://stackoverflow.com/q/5563349/456814). –  Jun 25 '14 at 04:57
  • Possible duplicate of [Migrate SVN repository with history to a new Git repository](http://stackoverflow.com/questions/79165/migrate-svn-repository-with-history-to-a-new-git-repository). –  Jun 25 '14 at 04:57

2 Answers2

1

A git clone won't create local branches for all the remote tracking branches by default.

Don't forget git for-each-ref when listing Git objects. The --format option can actually be an entire script.

For instance, to create local branches (local branches which don't exist yet) with upstream branch to a given remote (using also "Is there a better way to find out if a local git branch exists?"):

#!/bin/bash

aremote=$1
fmt='r=%(refname); T=$(r#refs/remotes/$aremote/}
if [[ "$T" != HEAD ]]; then
  git show-ref --verify --quiet refs/heads/$T
  res=$?
  if [[ "$res" != "0" ]] ; then git branch --set-upstream $T $aremote/$T ; fi
fi
'
e=`git for-each-ref --shell --format="$fmt" refs/remotes/$aremote`
eval "e"

You would use that script with the name of your remote as parameter.

Community
  • 1
  • 1
VonC
  • 1,042,979
  • 435
  • 3,649
  • 4,283
0

Cloning over HTTP (without using the smart server) uses some extra metadata that is generated from the rest of the repository. This metadata needs to be manually updated, which you can do by running git update-server-info.

jelmer
  • 2,280
  • 13
  • 25