2010-02-20 12 views
8

Quiero rastrear una rama maestra remota desde un nuevo repositorio remoto. Ambos ya existen.Sucursal de seguimiento remoto de configuración de Git

¿Cómo hago esto en git? Parece que no puedo hacerlo bien. Probé:

git remote add otherRepo git://... 
git branch -t myTrack otherRepo/master 

Sin embargo, me sale el siguiente error:

fatal: Not a valid object name: 'otherRepo/master'.

+3

hizo usted 'git fetch otherRepo' antes de intentar expandirse? 'git remote add' simplemente configura el control remoto, no hace una búsqueda de forma automática. Si ya la ha buscado, ¿está seguro de que tiene una rama llamada maestro? 'git branch -r' o' git remote muestra -n otherRepo' (* después de recuperarlo *) para verificar qué ramas tiene. –

+0

@crhis: gracias, ahora funciona. Parece lógico que necesite buscar, sin embargo, esto agrega, todas las otras ramas de otherRepo también. ¿Puedo obtener otroRepo/Master? No quiero desordenar la sucursal -r. –

Respuesta

12

Como se describe en los comentarios: git remote add otherRepo … solo configura el control remoto, no extrae nada de él. Tendrá que ejecutar git fetch otherRepo para buscar las ramas del repositorio remoto antes de poder crear ramas locales basadas en ellas.


(respondiendo a hacer más comentarios por OP)

Si sólo desea hacer un seguimiento de una sola rama del repositorio remoto, puede volver a configurar su propiedad a distancia del fetch (remote.otherRepo.fetch).

# done as a shell function to avoid repeating the repository and branch names 
configure-single-branch-fetch() { 
    git config remote."$1".fetch +refs/heads/"$2":refs/remotes/"${1}/${2}" 
} 
configure-single-branch-fetch "$remoteName" "$branch" 
# i.e. # configure-single-branch-fetch otherRepo master 

Después de esto, git fetch otherRepo sólo se ha podido recuperar la master rama del repositorio remoto en el otherRepo/master ‘rama de seguimiento remoto’ en su repositorio local.

Para la limpieza de los otros 'seguimiento sucursales remotas', se podría eliminar a todos ellos y vuelva a recuperar simplemente el que usted desea, o se puede borrar de forma selectiva todos ellos, excepto solamente desde el que desea:

git for-each-ref --shell --format='git branch -dr %(refname:short)' refs/remotes/otherRepo | sh -nv 
# remove the -nv if the commands look OK, then 
git fetch otherRepo 

# OR 

git for-each-ref --shell --format='test %(refname:short) != otherRepo/master && git branch -dr %(refname:short)' refs/remotes/otherRepo | sh -nv 
# remove the -nv if the commands look OK 

Si decide que desea rastrear más de una rama remota, pero no todas, puede tener múltiples configuraciones de búsqueda (con git config --add remote."$remoteName".fetch … o usando git config --edit para duplicar y editar directamente la línea en el archivo de configuración de su repositorio).

Si también desea evitar la búsqueda de etiquetas desde el control remoto, configure la propiedad de control remoto de su control remoto (remote.otherRepo.tagopt).

git config remote."$remoteName".tagopt --no-tags 
# i.e. # git config remote.otherRepo.tagopt --no-tags 
+0

gracias por esta respuesta tan completa. Parece horrible que una operación tan fácil se haga tan compleja. Lo que sea –

4

Usted podría intentar

git checkout -b myTrack otherRepo/master 

Esto creará un nuevo myTrack rama, que sigue la rama/maestro otherRepo.

+0

No funciona, el error es: fatal: git checkout: la actualización de rutas no es compatible con el cambio de ramas. ¿Ha pensado en pagar 'otherRepo/master' que no se puede resolver como commit? ' –

+0

Funcionó para mí después de hacer el complemento remoto y la búsqueda. – Von

Cuestiones relacionadas