DEV Community

Nočnica Mellifera for Heroku

Posted on • Updated on

Bash tip of the day: lazygit

Last week I asked which bash aliases you like to use and got a ton of great responses. One that had almost universal benefit was lazygit, from Mishal:

function lazygit() {
   local message="$1"
   local push_branch="${2:-$(git rev-parse --abbrev-ref HEAD)}"
   echo "Commit Message: $message"
   echo "Push Branch: ${push_branch}"
   git add --all
   git commit -m "$message"
   git push origin "$push_branch"
}

Enter fullscreen mode Exit fullscreen mode

I added it to bash as soon as I saw it, try it yourself!

If you have improvements or other aliases/functions for bash that you love, comment below!

Top comments (17)

Collapse
 
wulymammoth profile image
David

It's best to practice non-lazy Git and be explicit when you actually want to add everything. Hygienic commit messages allow you and other developers to really glean information about a series if commits.

If it's just work-in-progress, then commit as such with a WIP commit and then come back to and squash into logical commits

Collapse
 
nocnica profile image
Nočnica Mellifera

I think I should have clarified that you shouldn’t use lazygit on anything but your own demo projects. Hopefully the name makes it obvious :)

I should write something about git best practices!

Collapse
 
wulymammoth profile image
David

That's fair -- although, I practice this in my personal projects as well as I always like a clean history, but everything for humans is habitual. Defaulting to thinking and atomic commits carries over into daily work IMO :)

But I'm a bit extreme, too, as I'm almost alias-less. I always type the verbose git command

Collapse
 
mzaini30 profile image
Zen

If me:

git status
git add -A .
git commit -m "Upload"
git push
Collapse
 
vlasales profile image
Vlastimil Pospichal

Why . at the end of git add?

Collapse
 
mzaini30 profile image
Zen

For select all files.

Thread Thread
 
vlasales profile image
Vlastimil Pospichal

Usually I don't want to select all files, especially if I want to split commit into more independent steps.

Collapse
 
jimmymcbride profile image
Jimmy McBride

I've created some bash scripts similar to Zen's as well:

Filename: gitit

git add .
git commit -m "$1"
git push

Example: gitit "init commit"

I also have one for creating new branches and pushing their upstream:

Filename: branch

git checkout -b "$1"
git push origin -u "$1"

I always use branch to make new branches that way when I use gitit to push up so it works without fail. I have a few more, but those are my most used bash scripts I use in my git flow

Collapse
 
vlasales profile image
Vlastimil Pospichal • Edited

I am not lazy. First I run git status to see what has been modified, and/or git diff. Then git add what I want to have as part of the commit (usually git add -A, but sometime a cherry-pick is needed). Only then will I perform a git commit and a git push.

Working with Git requires some care. I use aliases, of course.

Collapse
 
spiritupbro profile image
spiritupbro

i thought at first you talk about open source program called lazygit

GitHub logo jesseduffield / lazygit

simple terminal UI for git commands

A simple terminal UI for git commands

GitHub Releases Go Report Card Codacy Badge Codacy Badge GolangCI GitHub tag homebrew

commit_and_push

Sponsors

Maintenance of this project is made possible by all the contributors and sponsors. If you'd like to sponsor this project and have your avatar or company logo appear below click here. 💙

Mark LussierDean HerbertPeter BjorklundReilly WoodOliver GüntherPawan DhananjayBartłomiej DachDavid KarlssonCarsten GehlingCEUKAkos PutzXeteraHolden LucasChau TranmatejciktheAverageDev (Luca Tumedei)Zach FullerIvan ZaitsevNicholas CloudLightQuantumAliaksandr StelmachonakBurgy BenjaminJoe KlemmerTobias LütkeBen BeaumontHollyJames SantucciJeff ForcierMaciej T. NowakMichael HuggettFarzad MajidfayyazYuryAndreas KurthBraden SteffaniakJordan GillardSebastianGeorge SpanosBen HuntAlex BradnerFrantisek StankoRobert Clancy (Robbo)Andy SlezakMartin KockIllarion KoperskiJesse AlamaDaniel KokottCodacyBrettJan HeijmansKevin Nowaldsem pruijsOmar Luq Ethan LiBrian MacAskillRaheel JunaidMaxinbrDon DavisFrancesco PiraJan ZenknerthedevdadVictor AremuRo Santalla

Elevator Pitch

Rant time: You've heard it before, git is powerful, but what good is that power when everything is so damn hard to do? Interactive rebasing requires you to edit a goddamn TODO file in your editor? Are you kidding me? To stage part of a file you need to use a command line program to step…




Collapse
 
pgronkievitz profile image
Info Comment hidden by post author - thread only accessible via permalink
Patryk Gronkiewicz

alias lazygit=lazygit that's totally unnecessary

Collapse
 
jimmymcbride profile image
Jimmy McBride • Edited

That's actually pretty cool! I'm going to apopt that.

Collapse
 
nomade55 profile image
Lucas G. Terracino

I've been creating scripts lately to ease my development, and amazingly I've never thought about this, is dead simple and useful.

Collapse
 
bhupesh profile image
Bhupesh Varshney 👾

Do you mind explaining what's the usecase for this ?

Collapse
 
nocnica profile image
Nočnica Mellifera

If you’re working on a solo project and just want to use git as a backup system, this lets you enter a single command to send all current changes up to your repository.

Collapse
 
nocnica profile image
Nočnica Mellifera

Love this. Do you mind if I share it in next week’s bash tip? I’ll of course link to your great article

 
nocnica profile image
Nočnica Mellifera

Totally agree that empowerment should be the theme.

And yeah that alias line is unnecessary! I’ll cut it.

Some comments have been hidden by the post's author - find out more