Skip to main content

Git

Whatโ€‹

Display git information when in a git repository. Also works for subfolders. For maximum compatibility, make sure your git executable is up-to-date (when branch or status information is incorrect for example).

tip

PowerShell offers support for the posh-git module for autocompletion, but it is disabled by default. To enable this, set $env:POSH_GIT_ENABLED = $true in your $PROFILE after initializing Oh My Posh. This will also make use of the posh-git output rather than do additional work to get the git status.

If you want to display the default posh-git output, do not set the above environment variable and add the following snippet after initializing Oh My Posh in your $PROFILE:

function Set-PoshGitStatus {
$global:GitStatus = Get-GitStatus
$env:POSH_GIT_STRING = Write-GitStatus -Status $global:GitStatus
}
New-Alias -Name 'Set-PoshContext' -Value 'Set-PoshGitStatus' -Scope Global -Force

You can then use the POSH_GIT_STRING environment variable in a text segment:

"template": "{{ if .Env.POSH_GIT_STRING }} {{ .Env.POSH_GIT_STRING }} {{ end }}"

Sample Configurationโ€‹

{
"type": "git",
"style": "powerline",
"powerline_symbol": "๎‚ฐ",
"foreground": "#193549",
"background": "#ffeb3b",
"background_templates": [
"{{ if or (.Working.Changed) (.Staging.Changed) }}#FFEB3B{{ end }}",
"{{ if and (gt .Ahead 0) (gt .Behind 0) }}#FFCC80{{ end }}",
"{{ if gt .Ahead 0 }}#B388FF{{ end }}",
"{{ if gt .Behind 0 }}#B388FB{{ end }}"
],
"template": "{{ .UpstreamIcon }}{{ .HEAD }}{{if .BranchStatus }} {{ .BranchStatus }}{{ end }}{{ if .Working.Changed }} ๏„ {{ .Working.String }}{{ end }}{{ if and (.Working.Changed) (.Staging.Changed) }} |{{ end }}{{ if .Staging.Changed }} ๏† {{ .Staging.String }}{{ end }}{{ if gt .StashCount 0 }} ๏ƒ‡ {{ .StashCount }}{{ end }}",
"properties": {
"fetch_status": true,
"fetch_upstream_icon": true,
"untracked_modes": {
"/Users/user/Projects/oh-my-posh/": "no"
}
}
}

Propertiesโ€‹

Fetching informationโ€‹

As doing multiple git calls can slow down the prompt experience, we do not fetch information by default. You can set the following properties to true to enable fetching additional information (and populate the template).

NameTypeDescription
fetch_statusbooleanfetch the local changes - defaults to false
ignore_status[]stringdo not fetch status for these repo's. Uses the repo's root folder and same logic as the exclude_folders property
fetch_upstream_iconbooleanfetch upstream icon - defaults to false
fetch_bare_infobooleanfetch bare repo info - defaults to false
untracked_modesmap[string]stringmap of repo's where to override the default untracked files mode:
  • no
  • normal
  • all
For example "untracked_modes": { "/Users/me/repos/repo1": "no" } - defaults to normal for all repo's. If you want to override for all repo's, use * to set the mode instead of the repo path
ignore_submodulesmap[string]stringmap of repo's where to change the --ignore-submodules flag (none, untracked, dirty or all). For example "ignore_submodules": { "/Users/me/repos/repo1": "all" }. If you want to override for all repo's, use * to set the mode instead of the repo path
native_fallbackbooleanwhen set to true and git.exe is not available when inside a WSL2 shared Windows drive, we will fallback to the native git executable to fetch data. Not all information can be displayed in this case. Defaults to false
fetch_userUserfetch the current configured user for the repository - defaults to false
status_formatsmap[string]stringa key, value map allowing to override how individual status items are displayed. For example, "status_formats": { "Added": "Added: %d" } will display the added count as Added: 1 instead of +1. See the Status section for available overrides. Defaults to an empty map.

Iconsโ€‹

Branchโ€‹

NameTypeDescription
branch_iconstringthe icon to use in front of the git branch name - defaults to \uE0A0
branch_identical_iconstringthe icon to display when remote and local are identical - defaults to \u2261
branch_ahead_iconstringthe icon to display when the local branch is ahead of its remote - defaults to \u2191
branch_behind_iconstringthe icon to display when the local branch is behind its remote - defaults to \u2193
branch_gone_iconstringthe icon to display when there's no remote branch - defaults to \u2262
branch_max_lengthintthe max length for the displayed branch name where 0 implies full length - defaults to 0
truncate_symbolstringthe icon to display when a branch name is truncated - defaults to empty
NameTypeDescription
commit_iconstringicon/text to display before the commit context (detached HEAD) - defaults to \uF417
tag_iconstringicon/text to display before the tag context - defaults to \uF412
rebase_iconstringicon/text to display before the context when in a rebase - defaults to \uE728
cherry_pick_iconstringicon/text to display before the context when doing a cherry-pick - defaults to \uE29B
revert_iconstringicon/text to display before the context when doing a revert - defaults to \uF0E2
merge_iconstringicon/text to display before the merge context - defaults to \uE727
no_commits_iconstringicon/text to display when there are no commits in the repo - defaults to \uF594

Upstreamโ€‹

NameTypeDescription
github_iconstringicon/text to display when the upstream is Github - defaults to \uF408
gitlab_iconstringicon/text to display when the upstream is Gitlab - defaults to \uF296
bitbucket_iconstringicon/text to display when the upstream is Bitbucket - defaults to \uF171
azure_devops_iconstringicon/text to display when the upstream is Azure DevOps - defaults to \uEBE8
codecommit_iconstringicon/text to display when the upstream is AWS CodeCommit - defaults to \uF270
git_iconstringicon/text to display when the upstream is not known/mapped - defaults to \uE5FB
upstream_iconsmap[string]stringa key, value map representing the remote URL (or a part of that URL) and icon to use in case the upstream URL contains the key. These get precedence over the standard icons

Template (info)โ€‹

default template
{{ .HEAD }}{{if .BranchStatus }} {{ .BranchStatus }}{{ end }}{{ if .Working.Changed }} \uF044 {{ .Working.String }}{{ end }}{{ if and (.Staging.Changed) (.Working.Changed) }} |{{ end }}{{ if .Staging.Changed }} \uF046 {{ .Staging.String }}{{ end }}

Propertiesโ€‹

NameTypeDescription
.RepoNamestringthe repo folder name
.WorkingStatuschanges in the worktree (see below)
.StagingStatusstaged changes in the work tree (see below)
.HEADstringthe current HEAD context (branch/rebase/merge/...)
.Refstringthe current HEAD reference (branch/tag/...)
.Behindintcommits behind of upstream
.Aheadintcommits ahead of upstream
.BranchStatusstringthe current branch context (ahead/behind string representation)
.Upstreamstringthe upstream name (remote)
.UpstreamGonebooleanwhether the upstream is gone (no remote)
.UpstreamIconstringthe upstream icon (based on the icons above)
.UpstreamURLstringthe upstream URL for use in hyperlinks in templates: {{ url .UpstreamIcon .UpstreamURL }}
.StashCountintthe stash count
.WorktreeCountintthe worktree count
.IsWorkTreebooleanif in a worktree repo or not
.IsBarebooleanif in a bare repo or not, only set when fetch_bare_info is set to true
.Dirstringthe repository's root directory
.Krakenstringa link to the current HEAD in GitKraken for use in hyperlinks in templates {{ url .HEAD .Kraken }}
.CommitCommitHEAD commit information (see below)
.Detachedbooleantrue when the head is detached
.Mergebooleantrue when in a merge
.Rebasebooleantrue when in a rebase
.CherryPickbooleantrue when in a cherry pick
.Revertbooleantrue when in a revert
.LatestTagstringthe latest tag name

Statusโ€‹

NameTypeDescription
.Unmergedintnumber of unmerged changes
.Deletedintnumber of deleted changes
.Addedintnumber of added changes
.Modifiedintnumber of modified changes
.Untrackedintnumber of untracked changes
.Changedbooleanif the status contains changes or not
.Stringstringa string representation of the changes above

Local changes use the following syntax:

IconDescription
xUnmerged
-Deleted
+Added
~Modified
?Untracked

Commitโ€‹

NameTypeDescription
.AuthorUserthe author of the commit (see below)
.CommitterUserthe comitter of the commit (see below)
.Subjectstringthe commit subject
.Timestamptime.Timethe commit timestamp
.Shastringthe commit SHA1

Userโ€‹

NameTypeDescription
.Namestringthe user's name
.Emailstringthe user's email