Skip to content

Instantly share code, notes, and snippets.

@zax4r0
Last active May 26, 2025 06:30
Show Gist options
  • Select an option

  • Save zax4r0/f17ee0249f87a9fcd83dd5b75008c2d1 to your computer and use it in GitHub Desktop.

Select an option

Save zax4r0/f17ee0249f87a9fcd83dd5b75008c2d1 to your computer and use it in GitHub Desktop.
Smart Git Changelog Alias

πŸ”§ Advanced Git Changelog Alias

Generate clean, conventional changelogs from your current branch vs master, with optional --author and --name flags.


πŸ“‹ Add the alias

git config --global alias.changelog '!f() { author=""; show_name="false"; while [ $# -gt 0 ]; do case "$1" in --author) author="--author=$2"; shift 2 ;; --name) show_name="true"; shift ;; *) break ;; esac; done; if [ "$show_name" = "true" ]; then git log master..HEAD --pretty=format:"- %s (@%an) (%h)" --no-merges --first-parent $author --grep="^feat\\|^fix\\|^docs\\|^style\\|^refactor\\|^perf\\|^test\\|^chore"; else git log master..HEAD --pretty=format:"- %s (%h)" --no-merges --first-parent $author --grep="^feat\\|^fix\\|^docs\\|^style\\|^refactor\\|^perf\\|^test\\|^chore"; fi; }; f'

πŸ“ What it does

  • Compares current branch with master.

  • Filters for conventional commit types:

    • feat, fix, docs, style, refactor, perf, test, chore
  • Supports:

    • --author "Name" β€” filter by author.
    • --name β€” append Git author username (as @Name).
  • Excludes merge commits.

  • Uses only first-parent commits.


▢️ Usage

Basic changelog:

git changelog

Filter by author:

git changelog --author "Alice"

Include author Git name (e.g., @Alice):

git changelog --name

Combine both:

git changelog --author "Alice" --name

βœ… Example Output

Basic:

- feat: add user profile page (a1b2c3d)
- fix: resolve login redirect loop (d4e5f6g)
- docs: update README with setup instructions (h7i8j9k)

With --name:

- feat: add user profile page (@alice) (a1b2c3d)
- fix: resolve login redirect loop (@bob) (d4e5f6g)
- docs: update README with setup instructions (@alice) (h7i8j9k)

With --author "Alice" --name:

- feat: add user profile page (@alice) (a1b2c3d)
- docs: update README with setup instructions (@alice) (h7i8j9k)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment