如何让git回购记得所有的遥控器? [英] How to make git repo remember all remotes?

查看:137
本文介绍了如何让git回购记得所有的遥控器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个git repo,这是另一个repo的分支。通常情况下,我通常会添加一个名为upstream的远程服务器,这是我从中分出的原始数据库。

  $ git remote -v 
origin git@github.com:skela / awesomeproject.git(fetch)
origin git@github.com:skela / awesomeproject.git(推送)
上游git://github.com /bob/awesomeproject.git(fetch)
上游git://github.com/bob/awesomeproject.git(推送)

是否有任何方法让这个额外的远程存储在克隆中?
说我删除我的本地存储库并执行:

  git clone git@github.com:skela / awesomeproject。 git 

现在我重新检查我的遥控器:

  $ git remote -v 
git@github.com:skela / awesomeproject.git(fetch)
git git@github.com:skela / awesomeproject。 git(push)



如何确保我的git repo始终保留这两个远程别名?



编辑:
只需添加我想要执行的主要原因这是为了将某些答案形成一个可接受的路径;)

目标是在我的回购中有一个分支,用于跟踪上游主人。

  [remoteupstream] 
url = git://github.com/bob/awesomeproject.git
fetch = + refs / heads / *:refs / remotes / upstream / *
[branchfather]
remote = upstream
merge = refs / heads / master

换句话说,在我的回购库中的分支father跟踪称为上游主分支的远程设备。



它一切正常我设置了它,但只要我再次克隆回购,父分支指向原点而不是上游。

解决方案

这是不可能的。 Git只克隆回购的内容,从来不是设置。如果您想将遥控器硬连线到您的回购站(它是否是个好主意),请在您的回购根目录中创建一个脚本 repo-setup.sh 这样做:

  git remote rm origin 
git remote rm upstream
git remote add origin git @ github.com:skela / awesomeproject.git
git remote add upstream git://github.com/bob/awesomeproject.git

在克隆存储库后运行此文件。


I have a git repo that is a fork of another repo. As a rule I will normally add a remote called upstream, which is the original repo I forked from.

$ git remote -v
origin git@github.com:skela/awesomeproject.git (fetch)
origin git@github.com:skela/awesomeproject.git (push)
upstream git://github.com/bob/awesomeproject.git (fetch)
upstream git://github.com/bob/awesomeproject.git (push)

Is there any way to have this additional remote persist across clones? Say I delete my local repository and do a:

git clone git@github.com:skela/awesomeproject.git

And now I recheck my remotes:

$ git remote -v
origin git@github.com:skela/awesomeproject.git (fetch)
origin git@github.com:skela/awesomeproject.git (push)

My upstream remote has vanished!

How to I ensure that my git repo always keeps these 2 remote aliases?

Edit: Just adding the main reason why I want to do this as to shape some of the answers down an acceptable path ;)

Goal is to have a branch in my repo that tracks the upstream's master.

[remote "upstream"]
    url = git://github.com/bob/awesomeproject.git
    fetch = +refs/heads/*:refs/remotes/upstream/*
[branch "father"]
    remote = upstream
    merge = refs/heads/master

In other words, the branch "father" which is in my repo tracks the remote called upstream's master branch.

It all works great once I set it up, but as soon as I clone the repo again, the "father" branch points to origin instead of the upstream.

解决方案

That is impossible. Git only clones the repo’s content, never it’s settings. If your want to hard-wire remotes into your repo (it stands to question whether this is a good idea), create a script repo-setup.sh in your repo root that does something like this:

git remote rm origin
git remote rm upstream
git remote add origin git@github.com:skela/awesomeproject.git
git remote add upstream git://github.com/bob/awesomeproject.git

The run this file after you cloned the repository.

这篇关于如何让git回购记得所有的遥控器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆