仅为一个分支设置远程?

时间:2017-01-24 13:59:04

标签: git

我需要使用远程存储库并将其设置为本地分支,但每次我想从远程仓库更新分支时都需要输入URL。有没有办法只为那个分支更改原点?因此,要更新分支机构,我不必使用该网址。

我目前的工作:

Wide view:
<br/>
<div class="table">
  <div class="row">
    <div class="td td1">1</div>
    <div class="td td2">2</div>
  </div>
  <div class="row">
    <div class="td td3">3</div>
    <div class="td td4">4</div>
  </div>
</div>

<hr/>Narrow view:
<br/>
<div class="table narrow">
  <div class="row">
    <div class="td td1">1</div>
    <div class="td td2">2</div>
  </div>
  <div class="row">
    <div class="td td3">3</div>
    <div class="td td4">4</div>
  </div>
</div>

但我只是做一些像:

git fetch https://github.com/username/repo branch:my-local-branch

以上内容将从git fetch my-local-branch 获取。

4 个答案:

答案 0 :(得分:3)

origin只是一个恰好是传统默认名称的任意名称。但您可以根据需要添加任意数量的远程存储库。只需使用git remote add username https://github.com/username/repo,即可使用git branch --set-upstream-to=username/branch my-local-branch配置本地分支的上游。

从那时起,您可以使用git pullgit pull --rebase中的my-local-branchgit fetch username/branch来从该存储库中获取远程分支。

答案 1 :(得分:2)

执行git fetch <brname>时,git会查询branch.<brname>.fetch配置变量以查看要从哪个远程获取。因此,您需要:

  1. 如果您还没有新遥控器,请添加它:
    git remote add <remname> https://github.com/username/repo.git
  2. 通过设置配置变量
    • 手动修改.git/config
    • 使用git config
    • 使您的分支track成为远程分支:
      git branch -u <remname>/<brname> <brname>
      (请注意,跟踪远程分支不仅仅是默认情况下,它可能会或可能不是您想要的。)

答案 2 :(得分:0)

使用以下两个分支:(默认情况下)和本地(根据需要使用您的姓名)

git branch local

git checkout local

现在你在本地分支机构。在这里进行更改并最后将其合并为:

git merge local

或直接将其移动到您需要的远程

您可以创建 n-number 的遥控器

因此您可以添加远程并在其上推/拉本地更改:

git add remote add local_up <your url>

git push -u local_up master

答案 3 :(得分:0)

您可以使用例如从远程服务器跟踪单个分支

git remote add theirname git://git.theirhost.com/theirrepo.git --track theirbranch

然后您可以 git fetch theirname 并且您将只获取 theirbranch 的提交以及引用这些提交的标签。

如果您查看 .git/config 文件内部,您会看到类似

[remote "theirname"]
url = git://git.theirhost.com/theirrepo.git
fetch = +refs/heads/theirbranch:refs/remotes/theirname/theirbranch

“秘方”是 fetch 引用。如果没有 --track,refspec 将是 +refs/heads/*:refs/remotes/theirname/*,而 * 会导致所有远程分支名称都被拉过来。

相关问题