posh-git colors not set for some local repos

151 Views Asked by At

I have two local repos for which I use posh-git, and in one of them, the branch colors show correctly according to the posh-git readme:

  • Cyan means the branch matches its remote
  • Green means the branch is ahead of its remote (green light to push)
  • Red means the branch is behind its remote
  • Yellow means the branch is both ahead of and behind its remote

But in my other repo, the branches are always in a cyan color, regardless of the state of local vs. remote.

Between the two, I've run a diff on both $GitPromptSettings and git config -l, and neither show any color-related differences (only the remote origin, some branch names, and one of them has some gitflow settings).

If it could make any difference, the two are also from two separate GitHub private (organization) repos.

What could be causing this, or what else could I do to troubleshoot?

1

There are 1 best solutions below

2
On BEST ANSWER

I suspect that your local branches aren't set to track anything upstream. This means that Git doesn't know which remote branches to compare them against.

You can check this by inspecting the .git/config file inside your repository. Branches that are set to track upstream branches will contain a merge setting, e.g.

[branch "master"]
        remote = origin
        merge = refs/heads/master

One easy way to set a tracking branch is to use the -u argument the next time you push, e.g. git push -u origin master. (You don't have to do this every time; this will set the option shown above the first time you use it).

From its documentation:

-u
--set-upstream

For every branch that is up to date or successfully pushed, add upstream (tracking) reference, used by argument-less git-pull and other commands. For more information, see branch.<name>.merge in git-config.

More information about setting a remote tracking branch on an existing branch can be found in this answer.