Question

The git branch --edit-description command opens a text editor for the user to manually enter the description of Git's current branch.

What I am after is something like:

git config branch.my_branch.description < <(fmt --width=72 <<MY_DESCRIPTION
Subject (50 chars max)

Intro (one sentence, line wraps after 72 chars)

Description (multiple paragraphs, line wraps after 72 chars)
MY_DESCRIPTION

According to the manpage git config --file=config-file is only for reading from or writing to a non-standard configuration file. Also the recent patch http://git.661346.n2.nabble.com/PATCH-config-git-config-from-file-handle-quot-quot-filename-as-stdin-td7603641.html does not aid in reading a configuration value from standard input.

Any ideas how to solve this problem in a simple way, ideally with Git built-ins? The latter is not a reqirement if that is not possible. Thanks for your valuable input.

Was it helpful?

Solution

You're on the right track with git config. The --edit-description option just sets branch.branchname.description in the default (local) git config file.

(The description is escape-sequence-encoded, but git config will do that for you.)

In shell-ese:

$ git config branch.my_branch.description 'Subject (50 chars max)

Intro (one sentence, line wraps after 72 chars)

Description (multiple paragraphs, line wraps after 72 chars)
MY_DESCRIPTION
'

does the trick. If you have a description in a file, such as /tmp/file:

$ git config branch.my_branch.description "$(cat /tmp/file)"

does it. Obviously you can replace cat with any other command, such as fmt, and you may use here-documents:

$ git config branch.my_branch.description "$(cat << END)"
some lines

of text

that wind up in the description.
END

(in my testing the encoded config entry for this last one does not end in a newline, but that seems to be OK, even though the other versions do end in a newline).


Edit: bash does not like the above here-document syntax; this seems to work:

cmd "$(cat << END
here-document text
goes here
END
)"

in both bash and /bin/sh, on my test system.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top