Can git permanently ignore a remote branch?

后端 未结 3 678
时光取名叫无心
时光取名叫无心 2020-12-07 00:11

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 t

相关标签:
3条回答
  • 2020-12-07 00:56

    Since git 2.29, released in october 2020, you can leverage negative refspec to exclude a specific branch to be fetched.

    For GitHub Pages, you can do it like so:

    git config --add remote.origin.fetch ^refs/heads/gh-pages
    

    You can read more about it on https://github.blog/2020-10-19-git-2-29-released/#user-content-negative-refspecs

    0 讨论(0)
  • 2020-12-07 00:57

    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
    
    0 讨论(0)
  • 2020-12-07 01:09

    I just hit the same problem. I was interested in one branch from 'bob', but he had many branches cluttering up my git branch -a output.

    I did this:

    rm .git/refs/remotes/bob/{next,master,maint}
    

    and the branches were gone. A git fetch might restore them though, but I don't intend to fetch from bob regularly.

    0 讨论(0)
提交回复
热议问题