Skip to content

Instantly share code, notes, and snippets.

@emmanuelnk
Last active February 19, 2025 14:48
Show Gist options
  • Select an option

  • Save emmanuelnk/818a810e5a65de1c77025df4c0ae88f2 to your computer and use it in GitHub Desktop.

Select an option

Save emmanuelnk/818a810e5a65de1c77025df4c0ae88f2 to your computer and use it in GitHub Desktop.

Revisions

  1. emmanuelnk revised this gist Feb 15, 2025. No changes.
  2. emmanuelnk revised this gist Feb 15, 2025. 2 changed files with 26 additions and 19 deletions.
    19 changes: 0 additions & 19 deletions git_recent.md
    Original file line number Diff line number Diff line change
    @@ -1,19 +0,0 @@
    An interactive version using [fzf][1]:
    - First install `fzf`

    ```bash
    brew install fzf
    ```

    - Then add the alias to `.gitconfig`

    ```
    recent = "!f() { branch=$(git for-each-ref --sort=-committerdate refs/heads --format='%(HEAD)%(refname:short)%09%(color:yellow)%(committerdate:relative)%09%(color:blue)%(subject)%09%(color:magenta)%(authorname)%(color:reset)' --color=always | column -ts$'\t' | fzf --ansi --delimiter=$'\t' --height=40% --reverse --prompt='Checkout> ' | cut -f1 | sed 's/^[* ]*//'); if [ -n \"$branch\" ]; then git checkout \"${branch%%[[:space:]]*}\"; fi; };
    ```

    Now you can just run `git recent`, and scroll through recent refs using arrow keys, `Enter` to checkout the branch or `Esc` to exit the menu

    ![image](https://raw.githubusercontent.com/emmanuelnk/transaction-service-iac/refs/heads/test-branch/test/CleanShot%202025-02-15%20at%2013.59.02.gif)


    [1]: https://junegunn.github.io/fzf/
    26 changes: 26 additions & 0 deletions interactive_git_recent.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    # Interactive Git Recent Menu

    An interactive alias using [fzf](https://junegunn.github.io/fzf) that shows most recent branches and gives you the ability to scroll and checkout the one you want (using `Enter`) or `Esc` to exit:
    - First install `fzf`

    ```bash
    brew install fzf
    ```

    - Then add the alias to `.gitconfig`

    ```
    [alias]
    recent = "!f() { branch=$(git for-each-ref --sort=-committerdate refs/heads --format='%(HEAD)%(refname:short)%09%(color:yellow)%(committerdate:relative)%09%(color:blue)%(subject)%09%(color:magenta)%(authorname)%(color:reset)' --color=always | column -ts$'\t' | fzf --ansi --delimiter=$'\t' --height=40% --reverse --prompt='Checkout> ' | cut -f1 | sed 's/^[* ]*//'); if [ -n \"$branch\" ]; then git checkout \"${branch%%[[:space:]]*}\"; fi; };
    ```

    Now you can just run `git recent`, and scroll through recent refs using arrow keys, `Enter` to checkout the branch or `Esc` to exit the menu

    ![image](https://raw.githubusercontent.com/emmanuelnk/transaction-service-iac/refs/heads/test-branch/test/CleanShot%202025-02-15%20at%2013.59.02.gif)

    ## Modifications
    - Column formatting is controlled by
    ```
    --format='%(HEAD)%(refname:short)%09%(color:yellow)%(committerdate:relative)%09%(color:blue)%(subject)%09%(color:magenta)%(authorname)%(color:reset)' --color=always
    ```
    Here you can change colors, the way the committerdate is displayed etc
  3. emmanuelnk revised this gist Feb 15, 2025. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion git_recent.md
    Original file line number Diff line number Diff line change
    @@ -13,7 +13,7 @@ recent = "!f() { branch=$(git for-each-ref --sort=-committerdate refs/heads --fo

    Now you can just run `git recent`, and scroll through recent refs using arrow keys, `Enter` to checkout the branch or `Esc` to exit the menu

    ![Image](https://github.com/user-attachments/assets/2d8aada8-afb4-4a4d-bd22-b0d80debecc7)
    ![image](https://raw.githubusercontent.com/emmanuelnk/transaction-service-iac/refs/heads/test-branch/test/CleanShot%202025-02-15%20at%2013.59.02.gif)


    [1]: https://junegunn.github.io/fzf/
  4. emmanuelnk created this gist Feb 15, 2025.
    19 changes: 19 additions & 0 deletions git_recent.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    An interactive version using [fzf][1]:
    - First install `fzf`

    ```bash
    brew install fzf
    ```

    - Then add the alias to `.gitconfig`

    ```
    recent = "!f() { branch=$(git for-each-ref --sort=-committerdate refs/heads --format='%(HEAD)%(refname:short)%09%(color:yellow)%(committerdate:relative)%09%(color:blue)%(subject)%09%(color:magenta)%(authorname)%(color:reset)' --color=always | column -ts$'\t' | fzf --ansi --delimiter=$'\t' --height=40% --reverse --prompt='Checkout> ' | cut -f1 | sed 's/^[* ]*//'); if [ -n \"$branch\" ]; then git checkout \"${branch%%[[:space:]]*}\"; fi; };
    ```

    Now you can just run `git recent`, and scroll through recent refs using arrow keys, `Enter` to checkout the branch or `Esc` to exit the menu

    ![Image](https://github.com/user-attachments/assets/2d8aada8-afb4-4a4d-bd22-b0d80debecc7)


    [1]: https://junegunn.github.io/fzf/