2020-10-05 02:33:12 -07:00
---
id: git
title: Git
sidebar_label: Git
---
## What
2021-06-03 10:55:08 -07:00
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).
Local changes can also be displayed which uses the following syntax for both the working and staging area:
2020-10-05 02:33:12 -07:00
- `+` added
- `~` modified
- `-` deleted
2020-12-31 11:08:16 -08:00
- `?` untracked
2020-10-05 02:33:12 -07:00
2021-09-01 04:45:33 -07:00
:::tip
2021-05-20 23:50:41 -07:00
PowerShell offers support for the `posh-git` module for autocompletion, but it is disabled by default.
2022-05-31 08:27:41 -07:00
To enable this, set `$env:POSH_GIT_ENABLED = $true` in your `$PROFILE`. Be aware this calls `git status`
twice, so in case you're having a slow repository, it's better to migrate to the [Posh-Git segment][poshgit].
2021-05-20 23:50:41 -07:00
:::
2022-08-09 23:42:18 -07:00
:::caution
2022-08-10 06:28:12 -07:00
Starting from version 3.152.0, `fetch_status` is disabled by default.
2021-05-29 04:37:05 -07:00
It improves performance but reduces the quantity of information. Don't forget to enable it in your theme if needed.
2022-05-31 08:27:41 -07:00
An alternative is to use the [Posh-Git segment][poshgit].
2021-05-28 04:28:00 -07:00
:::
2020-10-05 02:33:12 -07:00
## Sample Configuration
```json
{
"type": "git",
"style": "powerline",
2020-10-15 23:37:43 -07:00
"powerline_symbol": "\uE0B0",
2020-10-05 02:33:12 -07:00
"foreground": "#193549",
"background": "#ffeb3b",
2021-11-06 12:33:11 -07:00
"background_templates": [
2021-11-09 08:13:47 -08:00
"{{ 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 }}"
2021-11-06 12:33:11 -07:00
],
2022-09-06 22:01:52 -07:00
"template": "{{ .UpstreamIcon }}{{ .HEAD }}{{if .BranchStatus }} {{ .BranchStatus }}{{ end }}{{ if .Working.Changed }} \uF044 {{ .Working.String }}{{ end }}{{ if and (.Working.Changed) (.Staging.Changed) }} |{{ end }}{{ if .Staging.Changed }} \uF046 {{ .Staging.String }}{{ end }}{{ if gt .StashCount 0 }} \uF692 {{ .StashCount }}{{ end }}",
2020-10-05 02:33:12 -07:00
"properties": {
2021-11-06 12:33:11 -07:00
"fetch_status": true,
"fetch_stash_count": true,
2022-04-21 23:11:20 -07:00
"fetch_upstream_icon": true,
"untracked_modes": {
"/Users/user/Projects/oh-my-posh/": "no"
}
2020-10-05 02:33:12 -07:00
}
}
```
## Properties
2021-11-06 12:33:11 -07:00
### 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).
- fetch_status: `boolean` - fetch the local changes - defaults to `false`
- fetch_stash_count: `boolean` fetch stash count - defaults to `false`
- fetch_worktree_count: `boolean` fetch worktree count - defaults to `false`
2021-11-08 13:56:40 -08:00
- fetch_upstream_icon: `boolean` - fetch upstream icon - defaults to `false`
2022-06-30 09:01:53 -07:00
- untracked_modes: `map[string]string` - map of repo's where to override the default [untracked files mode][untracked] (`no` | `normal` | `all`). For example
2022-06-29 21:57:39 -07:00
`"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.
2022-06-30 09:01:53 -07:00
- ignore_submodules: `map[string]string` - map of repo's where to change the [--ignore-submodules][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.
2021-11-06 12:33:11 -07:00
### Icons
#### Branch
2020-10-11 10:28:29 -07:00
2020-11-27 10:45:53 -08:00
- branch_icon: `string` - the icon to use in front of the git branch name - defaults to `\uE0A0 `
2021-04-24 10:47:54 -07:00
- branch_identical_icon: `string` - the icon to display when remote and local are identical - defaults to `\u2261`
- branch_ahead_icon: `string` - the icon to display when the local branch is ahead of its remote - defaults to `\u2191`
- branch_behind_icon: `string` - the icon to display when the local branch is behind its remote - defaults to `\u2193`
2020-10-16 11:07:38 -07:00
- branch_gone_icon: `string` - the icon to display when there's no remote branch - defaults to `\u2262`
2021-05-29 04:37:05 -07:00
- branch_max_length: `int` - the max length for the displayed branch name where `0` implies full length - defaults to `0`
2021-11-18 10:58:57 -08:00
- truncate_symbol: `string` - the icon to display when a branch name is truncated - defaults to empty
2020-10-11 10:28:29 -07:00
2021-11-06 12:33:11 -07:00
#### HEAD
2020-10-11 10:28:29 -07:00
2020-10-16 11:07:38 -07:00
- commit_icon: `string` - icon/text to display before the commit context (detached HEAD) - defaults to `\uF417`
- tag_icon: `string` - icon/text to display before the tag context - defaults to `\uF412`
- rebase_icon: `string` - icon/text to display before the context when in a rebase - defaults to `\uE728 `
- cherry_pick_icon: `string` - icon/text to display before the context when doing a cherry-pick - defaults to `\uE29B `
2021-07-29 12:47:21 -07:00
- revert_icon: `string` - icon/text to display before the context when doing a revert - defaults to `\uF0E2 `
2020-10-16 11:07:38 -07:00
- merge_icon: `string` icon/text to display before the merge context - defaults to `\uE727 `
2020-12-31 11:08:16 -08:00
- no_commits_icon: `string` icon/text to display when there are no commits in the repo - defaults to `\uF594 `
2020-10-11 10:28:29 -07:00
2021-11-06 12:33:11 -07:00
#### Upstream
2020-10-11 10:28:29 -07:00
2020-10-16 11:07:38 -07:00
- github_icon: `string` - icon/text to display when the upstream is Github - defaults to `\uF408 `
- gitlab_icon: `string` - icon/text to display when the upstream is Gitlab - defaults to `\uF296 `
- bitbucket_icon: `string` - icon/text to display when the upstream is Bitbucket - defaults to `\uF171 `
2021-05-15 07:47:10 -07:00
- azure_devops_icon: `string` - icon/text to display when the upstream is Azure DevOps - defaults to `\uFD03 `
2020-10-16 11:07:38 -07:00
- git_icon: `string` - icon/text to display when the upstream is not known/mapped - defaults to `\uE5FB `
2020-10-18 03:30:27 -07:00
2022-02-01 03:10:46 -08:00
## Template ([info][templates])
:::note default template
``` template
2022-09-06 22:01:52 -07:00
{{ .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 }}{{ if gt .StashCount 0}} \uF692 {{ .StashCount }}{{ end }}{{ if gt .WorktreeCount 0}} \uf1bb {{ .WorktreeCount }}{{ end }}
2022-02-01 03:10:46 -08:00
```
:::
### Properties
2021-11-06 12:33:11 -07:00
2022-07-01 04:14:25 -07:00
- `.RepoName`: `string` - the repo folder name
2022-03-30 15:33:15 -07:00
- `.Working`: `GitStatus` - changes in the worktree (see below)
2021-11-09 08:13:47 -08:00
- `.Staging`: `GitStatus` - staged changes in the work tree (see below)
- `.HEAD`: `string` - the current HEAD context (branch/rebase/merge/...)
2022-07-14 10:53:00 -07:00
- `.Ref`: `string` - the current HEAD reference (branch/tag/...)
2021-11-09 08:13:47 -08:00
- `.Behind`: `int` - commits behind of upstream
- `.Ahead`: `int` - commits ahead of upstream
- `.BranchStatus`: `string` - the current branch context (ahead/behind string representation)
- `.Upstream`: `string` - the upstream name (remote)
2022-02-04 10:21:02 -08:00
- `.UpstreamGone`: `boolean` - whether the upstream is gone (no remote)
2021-11-09 08:13:47 -08:00
- `.UpstreamIcon`: `string` - the upstream icon (based on the icons above)
2022-01-28 04:42:34 -08:00
- `.UpstreamURL`: `string` - the upstream URL for use in [hyperlinks][hyperlinks] in templates: `{{ url .UpstreamIcon .UpstreamURL }}`
2021-11-09 08:13:47 -08:00
- `.StashCount`: `int` - the stash count
- `.WorktreeCount`: `int` - the worktree count
- `.IsWorkTree`: `boolean` - if in a worktree repo or not
2022-08-28 06:34:08 -07:00
- `.Dir`: `string` - the repository's root directory
2022-09-01 10:49:17 -07:00
- `.Kraken`: `string` - a link to the current HEAD in [GitKraken][kraken-ref] for use in [hyperlinks][hyperlinks] in templates `{{ url .HEAD .Kraken }}`
2021-11-06 12:33:11 -07:00
### GitStatus
- `.Unmerged`: `int` - number of unmerged changes
- `.Deleted`: `int` - number of deleted changes
- `.Added`: `int` - number of added changes
- `.Modified`: `int` - number of modified changes
- `.Changed`: `boolean` - if the status contains changes or not
- `.String`: `string` - a string representation of the changes above
2022-06-01 14:37:19 -07:00
[poshgit]: /docs/segments/poshgit
2022-04-20 09:43:59 -07:00
[templates]: /docs/configuration/templates
[hyperlinks]: /docs/configuration/templates#helper-functions
2022-06-30 09:01:53 -07:00
[untracked]: https://git-scm.com/docs/git-status#Documentation/git-status.txt---untracked-filesltmodegt
[submodules]: https://git-scm.com/docs/git-status#Documentation/git-status.txt---ignore-submodulesltwhengt
2022-09-01 10:49:17 -07:00
[kraken-ref]: https://www.gitkraken.com/invite/nQmDPR9D