git可以永久忽略远程分支? [英] Can git permanently ignore a remote branch?

查看:132
本文介绍了git可以永久忽略远程分支?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用GitHub的Pages功能。这可以通过将发布的HTML放入名为 gh-pages 的分支中。我有两个单独的工作目录,一个用于项目本身,另一个用于HTML文档。



在前者中,我想完全忽略 gh-pages 分支,因为它是一个不相关的工作,我不希望它混淆了我的各种提交可视化。



是,我有什么是:

$ $ p $ code $ git远程显示原点
远程原点
提取URL: git@github.com:reidpr / quac.git
推送URL:git@github.com:reidpr / quac.git
HEAD分支:master
远程分支:
bar被跟踪
foo跟踪
跟踪的gh页面
跟踪的主数据
为'git pull'配置的本地分支:
主控与远程主控合并
配置的本地控制'git push':
主人推动主人(最新)

以及我想要的是类似的:

  $ git re mote显示原点
[...]
远程分支:
跟踪的跟踪
跟踪的
gh页面忽略
跟踪的跟踪
[ ...]

请注意,我有一些分支希望跟踪,只有一个我不知道。我想指定后者,而不是前者。



我可以删除 origin / gh-pages ,但下一次我又回来了 git fetch

解决方案

您可以修改.gitconfig,因此它告诉 git 仅提取您想要的内容:

  fetch = + refs / heads / mybranch:refs / remotes / origin / mybranch 



<

  git fetch origin + refs / heads / mybranch:refs / remotes / origin / mybranch 

创建别名就像添加新的.gitconfig中的别名:

pre $ $ $ $ $ $ $ $ b $ myfetch = git fetch origin + refs / heads / mybranch:refs / remotes / origin / mybranch

更新:

你可以指定更多分支:

  git fetch orig in + refs / heads / master:refs / remotes / origin / master + refs / heads / develop:refs / remotes / origin / develop 


I'm using the Pages feature of GitHub. This works by putting the published HTML in a branch called gh-pages. I have two separate working directories, one for the project itself and one for the HTML docs.

In the former, I want to completely ignore the gh-pages branch, as it's an unrelated line of work and I don't want it to clutter up my various commit visualizations.

That is, what I have is:

$ git remote show origin
* remote origin
  Fetch URL: git@github.com:reidpr/quac.git
  Push  URL: git@github.com:reidpr/quac.git
  HEAD branch: master
  Remote branches:
    bar              tracked
    foo              tracked
    gh-pages         tracked
    master           tracked
  Local branches configured for 'git pull':
    master    merges with remote master
  Local refs configured for 'git push':
    master    pushes to master    (up to date)

and what I want is something like:

$ git remote show origin
  [...]
  Remote branches:
    bar              tracked
    foo              tracked
    gh-pages         ignored
    master           tracked
  [...]

Note there are several branches that I do want to track, and just one that I don't. I want to specify the latter, not the former.

I can delete the local references to origin/gh-pages, but then it comes back next time I git fetch.

解决方案

You can modify the .gitconfig, so it tells git to fetch only what you just want:

   fetch = +refs/heads/mybranch:refs/remotes/origin/mybranch

Also, you can create an alias for the fetch which fetches what you want:

 git fetch origin +refs/heads/mybranch:refs/remotes/origin/mybranch

The creation of an alias is as simple as adding the new alias in .gitconfig:

 [alias]
   myfetch= git fetch origin +refs/heads/mybranch:refs/remotes/origin/mybranch

UPDATE:

You can specify more branches of course:

 git fetch origin +refs/heads/master:refs/remotes/origin/master +refs/heads/develop:refs/remotes/origin/develop

这篇关于git可以永久忽略远程分支?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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