DEV Community

Discussion on: 🕵️‍♂️ Learn git alias and boost your productivity

Collapse
 
mfurquimdev profile image
Mateus Furquim •

I do have an alias that I use often. I call it git ld, which is short for git log diverged.

git config --global alias.ld "log --oneline --graph --decorate main $(git branch | grep "\*" | cut -d " " -f 2) $(git merge-base main $(git branch | grep "\*" | cut -d " " -f 2))^\!"
Enter fullscreen mode Exit fullscreen mode

Suppose your git flow consists of creating a branch from main, implementing some features, and merging it back to main.

In this scenario, you want to know if your branch has diverged from main.

Let's say git log shows something like this:

$ git log --oneline --graph --decorate --all
* c36d102 (main) New commit on main
| * f5003c8 (HEAD -> develop) New commit on develop
|/
* c484b40 Where it has diverged
* ec3124d Initial commit
Enter fullscreen mode Exit fullscreen mode

This output might be alright for few commits, but if there are more than a dozen, it starts getting polluted. The output of git ld is this:

$ git ld
* c36d102 (main) New commit on main
| * f5003c8 (HEAD -> develop) New commit on develop
|/
* c484b40 Where it has diverged
Enter fullscreen mode Exit fullscreen mode

OBS: I took most of this code from a StackOverflow answer that I cannot find. If I do find, I will edit to include the source.

Collapse
 
balastrong profile image
Leonardo Montini Playful Programming •

Looks really useful, thanks for sharing!