Home / Alt manpages / git-column(1)

  • git-column(1)
  • User command
  • linux

Turn Git Input into Predictable Columns with git column

You will finish with a repeatable way to format newline-separated input as a table, choose whether values fill down columns or across rows, and make the result fit a known width. The examples use Git 2.43.0, installed here from the git-man package version 1:2.43.0-1ubuntu7.3. Allow about ten minutes. You need Git and a shell; no repository or elevated privilege is required.

Checkpoint

This command formats data. It does not sort, change, or interpret the input. Each input line becomes one cell, so prepare the order before handing it to Git.

1. Confirm the installed command

Run these ordinary, read-only checks:

$ git --version
git version 2.43.0
$ git help column

The second command opens the local manual in your configured pager. The command is usually invoked as git column, even though its manual page is named git-column. If git help column cannot find it, check that the Git documentation package is installed. Do not use sudo to format ordinary input.

2. Format one value per input line

Use --mode=column when you want to fill the first column, then the second, working down the table. Set --width in scripts and examples so the output does not depend on the terminal in which it runs:

$ seq 1 12 | git column --mode=column --width=24 --padding=2
1   3   5   7   9   11
2   4   6   8   10  12

Here the input is twelve lines, and the width permits six columns. The values are not being numerically sorted. Git is preserving the input sequence while placing lines into cells. --padding=2 requests two spaces between columns; the displayed alignment also depends on the width of the cells.

Verify: compare the number and order of source lines before troubleshooting the table:

$ seq 1 12 | wc -l
12

3. Choose row-first layout when reading across is clearer

--mode=row fills the first row before moving to the next. This is useful for a short list where people scan left to right:

$ seq 1 12 | git column --mode=row --width=24 --padding=2
1   2   3   4   5   6
7   8   9   10  11  12

The width is a maximum layout width, not a request to truncate values. A long value can force fewer columns or make a table wider than the number you supplied. If output must fit a fixed interface, keep the input labels short and test with the longest expected label.

The third layout, plain, deliberately produces one cell per line. It is a useful escape hatch when columns would make copying or comparing values harder:

$ printf '%s\n' alpha beta gamma | git column --mode=plain
alpha
beta
gamma

4. Control the table boundary

Use the remaining formatting options only when a consumer needs a specific shape:

  • --width=<number> sets the terminal width used for layout. Without it, Git detects the terminal width and falls back to 80 when detection is unavailable.
  • --padding=<number> sets the spaces between columns. The default is one.
  • --indent=<text> prefixes every output line with the supplied text.
  • --nl=<text> replaces the line ending appended to each output line. Include an actual newline in the value when a downstream format needs one.

For example, this adds a prompt-like prefix and a semicolon after every formatted line:

$ printf '%s\n' red green blue | git column --mode=column --width=20 --indent='items: ' --nl=';' --padding=1
items: red  green  blue;

Be careful with --nl in shell commands. A quoted backslash-n is two characters, not a newline. When the output is intended for another program, prefer the default newline unless that program explicitly specifies another record separator.

5. Use Git configuration without losing the test

Git's column-aware commands consult column.ui and more specific settings such as column.branch, column.status, and column.tag. The column.ui value combines three decisions:

DecisionValuesEffect
Whenalways, never, autoAlways use columns, never use them, or use them only for terminal output.
Directioncolumn, row, plainFill down, fill across, or keep one value per line.
Spacingdense, nodenseAllow unequal column widths, or keep widths equal.

Test a configuration for one command with -c instead of changing your global file:

$ printf '%s\n' a b c d | git -c column.ui='always,row' column --command=demo --width=5 --padding=1
a  b
c  d

--command=demo tells git column to look up column.demo and then column.ui. The one-shot -c setting disappears when the command exits. If you decide to make a persistent change with git config --global, treat it as a user-environment change: record the old value first with git config --global --get column.ui, and undo a value you added with git config --global --unset column.ui. Do not copy a global setting into automation without deciding whether non-terminal output should remain stable.

6. Diagnose the usual surprises

If a pipeline appears to ignore columns, check whether it is reading from a terminal. Configuration set to auto intentionally behaves differently when output is redirected. For a deterministic pipeline, pass an explicit --mode and --width, or use a one-shot -c setting.

If values look reordered, inspect the mode first. column and row are both order-preserving, but they place the same sequence into different coordinates. If values are missing, inspect the producer and its exit status. Git column does not fetch, filter, or repair input.

If a label contains spaces, it remains one input line and therefore one cell. Quote the label when creating it in the shell, but do not expect git column to parse shell quoting from standard input. If a label contains a newline, it is two input cells by definition.

Finally, keep machine-readable output separate from presentation. Tables are suitable for a human terminal. For a script, consume the original newline-separated values unless the receiving interface explicitly requires the formatted layout. There is no destructive operation to undo in these examples, and no service restart or privileged action is needed.

Done means

  • You confirmed the installed Git version and local manual.
  • You chose column, row, or plain deliberately.
  • You set an explicit width and padding when output must be reproducible.
  • You know that each input line becomes one cell and that input order is preserved.
  • You tested configuration with git -c before considering a persistent change.
  • Your scripts keep data output separate from terminal presentation where possible.