Skip to content

Instantly share code, notes, and snippets.

@lbussy
Last active August 6, 2021 11:21
Show Gist options
  • Save lbussy/164ef592a1f00e1842f128465b2e3088 to your computer and use it in GitHub Desktop.
Save lbussy/164ef592a1f00e1842f128465b2e3088 to your computer and use it in GitHub Desktop.
Git Fetch Does Not Get Origin Branches

Get all Git Branches

When you git fetch sometimes you may not see all origin branches when you issue the command git branch -a or git branch -r.

This happens sometimes, if you change the remote repository with:

git remote set-url origin https://github.com/{owner}/{repository}

When this happens, exit .git/config and look for a hard-coded branch name in the origin:

[remote "origin"]
        url = https://github.com//{owner}/{repository}
        fetch = +refs/heads/{branch_name}:refs/remotes/origin/{branch_name}

Change it to a wild card:

[remote "origin"]
        url = https://github.com//{owner}/{repository}
        fetch = +refs/heads/*:refs/remotes/origin/*

Now, git fetch will properly grab references to the origin's branches.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment