Show graph log of branch, default repository branch, and their remote counterparts.
This is a shortcut to git log --graph which provides a middle ground between
showing only a given branch (which might lack context) and showing all branches
(which might get crowded on big projects).
git log --graph --oneline |
git log --graph --oneline --all |
|---|---|
![]() |
![]() |
git context-graph |
|---|
![]() |
This command is a shortcut to:
git log --color --graph --abbrev-commit --decorate --pretty=oneline \ my-branch origin/my-branch \ main origin/main
By default, a branch is shown along with the default repository branch (main / master),
their remote counterparts, plus any additional context branches you have configured.
Show the graph for the current branch:
git context-graphShow the graph for one or more specific branches:
git context-graph my-branch other-branchBy default, branch arguments replace the current branch as the graph's subject.
Use --add (-a) to add them to the current branch instead:
git context-graph --add other-branch # (-a) graph the current branch together with other-branchNarrow down what is shown:
git context-graph --local # only local branches (ignore remotes)
git context-graph --no-default # omit the default branch (main / master)Any git-log option can be passed through to refine or customize the output
(see the git-log documentation):
git context-graph --pretty=medium -- some/pathPassing a remote branch (e.g. origin/my-branch) focuses that single remote.
Counterparts on other remotes are left out of the graph (though they still appear as labels when they point at commits already shown).
git context-graph origin/my-branchInstead of drawing the graph, list the branches involved:
git context-graph --list # branches that would be shown in the graph
git context-graph --list --short # ... using short namesOn top of the branches shown by default, you can persist additional context branches per branch.
These are stored in the repository's local git config (under branch.<name>.context) and are automatically included
whenever you graph that branch.
Add branches to a context - --config-add (-A):
# git context-graph [<base_branch>...] -A|--config-add <additional_branch>...
git context-graph --config-add feature-a2 # add branch(es) to current branch context
git context-graph feature-a1 --config-add feature-a2 # ... or to a specific branch contextClear context branches - --config-clear (-C):
# git context-graph [<base_branch>...] -C|--config-clear [<additional_branch>...]
git context-graph --config-clear # clear all configured context branches for current branch
git context-graph --config-clear feature-a2 # ... or remove a specific branch from current branch context
git context-graph feature-a1 --config-clear # ... or clear all context branches for a specific branch
git context-graph feature-a1 --config-clear feature-a2 # ... or remove a specific branch from a specific branch contextToggle a branch in/out of a context - --config-toggle (-T):
# git context-graph [<base_branch>...] -T|--config-toggle <additional_branch>...
git context-graph --config-toggle feature-a3 # toggle a branch in/out of current branch contextSync a branch's context into a shared preset - --sync (-S):
# git context-graph [<base_branch>] [<config edit>] -S|--sync
git context-graph --sync # make every branch in the set reference the others
git context-graph --config-add feature-a3 --sync # ... or apply an edit, then propagate it to the whole presetUsed on its own, --sync mirrors a branch's context across the set so every member references all the others.
Combined with --config-add/--config-clear/--config-toggle, the edit is applied and then synced:
a branch removed from the preset is detached from every member (keeping only its unrelated context),
and clearing a branch's whole context tears the preset down.
Reset the whole repository's context configuration - --config-reset (-Z):
# git context-graph -Z|--config-reset
git context-graph --config-reset # remove all branch context configuration (asks for confirmation)To review context membership across the repository, list all local branches flagged by whether they belong to a branch's context:
# git context-graph [<base_branch>] -v|--list-status
git context-graph --list-status # all local branches, flagged by context membershipMarkers:
' * 'current / reference,'[*]'in context,'[ ]'not in context.
Example output:
* feature-a1 [*] feature-a2 [*] feature-a3 [ ] feature-b1 [ ] feature-b2
<base_branch>...
Branch(es) to show graph for. If omitted, current branch will be used.
-
-a|--add<additional_branch>...
Consider<additional_branch>argument(s) as additional branch(es) (added to current branch). -
--local
Show only local branches (ignore remotes). -
--no-default
Show only related branches (local and remote), without default branch. -
--fold|--unfold|--fold-toggle
Show first-parent history only (--fold) or the full graph (--unfold), or flip the current setting (--fold-toggle).
Folding mode is persisted to the local git configuration (context-graph.first-parent).
-
-l|--list
List branches that would be shown in the graph (does not display graph). -
-s|--short
Use short branch names when listing branches (withoutrefs/heads/orrefs/remotes/).
Implies--list. -
-v|--list-status
List local branches, flagging those in the current branch's context.
' * 'current / reference,'[*]'in context,'[ ]'not in context.
-
-A|--config-add<additional_branch>...
For a given branch, persist additional context branches to git configuration. -
-C|--config-clear[<additional_branch>...]
For a given branch, remove additional context branches from git configuration.
If no additional branch is passed, all configured additional branches will be removed. -
-T|--config-toggle<additional_branch>...
For a given branch, toggle specified branches from context in git configuration. -
-S|--sync
Synchronize a branch's context into a shared preset where every branch in the set references all the others.
Works on its own or propagates an edit to the whole preset (--config-add/--config-clear/--config-toggle).
A branch removed from the preset is detached from all its members, keeping only unrelated context. -
-Z|--config-reset
Remove all context-graph configuration from the repository (branch context, folding preference).
-h|--usage
Show command usage.
- Add the
git-context-graphdirectory to yourPATH
in one of your shell startup scripts:PATH="${PATH}:/path/to/git-context-graph"
OR
- Define it as a git alias:
run:or edit yourgit config --global alias.cg '!bash /path/to/git-context-graph/git-context-graph'~/.gitconfigdirectly:[alias] cg = "!bash /path/to/git-context-graph/git-context-graph"
Completion is available in git-context-graph-completion.bash. Source it in one of your shell startup scripts:
. "/path/to/git-context-graph/git-context-graph-completion.bash"git context-graph pairs well with Lazygit:
use it as the log command for the branch and all-branches views, and wire a couple of
custom keybindings to manage a branch's context without leaving the UI.
Point Lazygit's log views at git context-graph so they show each branch together with
its context, rather than a single branch or every branch at once:
git:
# Log shown for the selected branch
branchLogCmd: git context-graph {{branchName}} --
# Logs cycled through in the "all branches" status view
allBranchesLogCmds:
- git context-graph --first-parent --all --
- git context-graph --first-parent --reflog --
#- ...Any git-log option can be added (e.g. --pretty=custom-format).
Add a custom command to toggle merged branch folding in graph log view.
Suggestion: use <a> (same as "Show/cycle all branch logs" (allBranchesLogGraph) in status tab.
customCommands:
- key: '<a>'
context: 'localBranches,remoteBranches'
command: "git context-graph --fold-toggle"
description: "Toggle folding in branch graph log"
output: none![]() |
![]() |
Add custom commands to toggle a branch in/out of the selected branch's context and sync across preset branches from the local branches panel.
Toggle a branch in/out of the selected branch's context
The menu is built from --list-status, so it lists every local branch flagged by its current membership:
customCommands:
- key: '<alt+c>'
context: 'localBranches'
command: "git context-graph {{ .SelectedLocalBranch.Name }} --config-toggle {{ .Form.Branch }}"
description: "Toggle branch in current context"
output: log
prompts:
- type: 'menuFromCommand'
title: "Toggle branch in context of {{ .SelectedLocalBranch.Name }}"
key: 'Branch'
command: 'git context-graph {{ .SelectedLocalBranch.Name }} --list-status'
filter: '(?P<status>.*)\t(?P<branch>.*)'
valueFormat: '{{ .branch }}'
labelFormat: >-
{{ if eq .status " * " }}{{ .status | green | bold }} {{ .branch | underline }}{{ end }}
{{ if eq .status "[*]" }}{{ .status | green | bold }} {{ .branch | bold }}{{ end }}
{{ if eq .status "[ ]" }}{{ .status | white }} {{ .branch }}{{ end }}Toggle a branch and sync the whole preset
Same menu, but appends --sync so the toggle is mirrored across every branch of the preset:
- key: '<ctrl+alt+c>'
context: 'localBranches'
command: "git context-graph {{ .SelectedLocalBranch.Name }} --config-toggle {{ .Form.Branch }} --sync"
description: "Toggle branch in current context preset (+sync)"
output: log
prompts:
- type: 'menuFromCommand'
title: "Toggle branch in current context preset (+sync)"
key: 'Branch'
command: 'git context-graph {{ .SelectedLocalBranch.Name }} --list-status'
filter: '(?P<status>.*)\t(?P<branch>.*)'
valueFormat: '{{ .branch }}'
labelFormat: >-
{{ if eq .status " * " }}{{ .status | green | bold }} {{ .branch | underline }}{{ end }}
{{ if eq .status "[*]" }}{{ .status | green | bold }} {{ .branch | bold }}{{ end }}
{{ if eq .status "[ ]" }}{{ .status | white }} {{ .branch }}{{ end }}






