DEV Community

Álex Sáez
Álex Sáez

Posted on • Originally published at alexsaezm.com

Where are all the branches?!

Recently I started using gh for working with my forks. Before that I used to add the remotes manually.

When cloning a fork, gh adds the original repository as a upstream remote which is what I used to do manually, but if you try to find the branches, you'll find that it only tracks the default one.

For tracking all of the branches in the upstream remote too, you just need to find the fetch line under the upstream section in the .git/config file.

For example, this is the content of my .git/config after cloning my go fork:

$ cat .git/config 
[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
[remote "origin"]
    url = git@github.com:alexsaezm/go.git
    fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
    remote = origin
    merge = refs/heads/master
[remote "upstream"]
    url = git@github.com:golang/go.git
    fetch = +refs/heads/master:refs/remotes/upstream/master
Enter fullscreen mode Exit fullscreen mode

But what I really want under the upstream entry is this:

[remote "upstream"]
        url = git@github.com:golang/go.git
        fetch = +refs/heads/*:refs/remotes/upstream/*
Enter fullscreen mode Exit fullscreen mode

After changing that file, you can do a git fetch --all :)

Top comments (0)