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"
}
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 (20)
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 commitsI 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!
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
commandIf me:
Why
.
at the end ofgit add
?For select all files.
Usually I don't want to select all files, especially if I want to split commit into more independent steps.
I've created some bash scripts similar to Zen's as well:
Filename:
gitit
Example:
gitit "init commit"
I also have one for creating new branches and pushing their upstream:
Filename:
branch
I always use
branch
to make new branches that way when I usegitit
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 flowI am not lazy. First I run
git status
to see what has been modified, and/orgit diff
. Thengit add
what I want to have as part of the commit (usuallygit add -A
, but sometime a cherry-pick is needed). Only then will I perform agit commit
and agit push
.Working with Git requires some care. I use aliases, of course.
I've been creating scripts lately to ease my development, and amazingly I've never thought about this, is dead simple and useful.
alias lazygit=lazygit
that's totally unnecessaryi thought at first you talk about open source program called lazygit
simple terminal UI for git commands
lazygit
A simple terminal UI for git commands, written in Go with the gocui library.
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 through each hunk and if a hunk can't be split down any further but contains code you don't want to stage, you have to edit an arcane patch file by hand? Are you KIDDING me?! Sometimes you get asked to stash your changes when switching branches only to realise that after you switch and unstash that there weren't even any conflicts and it would have been fine to just checkout the branch directly? YOU HAVE GOT TO…
That's actually pretty cool! I'm going to apopt that.
Love this. Do you mind if I share it in next week’s bash tip? I’ll of course link to your great article
Do you mind explaining what's the usecase for this ?
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.
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