3

Is there a way to write an alias that adds current date to name of new branch?

For example:

git branch-today new_branch_name

should create new branch with 22_09_2015_new_branch_name name.

Andrii Iushchuk
  • 376
  • 1
  • 9
  • Wherever possible, please use YYYY-MM-DD ([ISO 8601](http://www.iso.org/iso/home/standards/iso8601.htm)). The date format you have chosen (DD_MM_YYYY) is ambiguous. – Jared Beck Sep 22 '15 at 15:51
  • @JaredBeck Strictly speaking, YYYY-MM-DD is just as ambiguous as DD_MM_YYYY. 1999-01-02 could be the second day of January, or the first day of February. It's not the format or the order of the components that makes it unambiguious - it's the agreed-upon interpretation of the format that makes it unambiguous. Thus, as long as all users of DD_MM_YYYY agree upon a "standard" interpretation, that format is just as valid as your ISO proposal. That said, I do tend to prefer ISO 8601-like formats for sortability... – twalberg Sep 22 '15 at 18:46

1 Answers1

3

Create a git alias and add it to your .gitconfig

[alias]
        branch-today = "!bt() { git branch $(date +%d-%m-%Y)_$1;}; bt"

git branch-today foo

Git branch output:

  22-09-2015_foo
* master
pcantalupo
  • 2,212
  • 17
  • 27