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 (17)
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 thought at first you talk about open source program called lazygit
jesseduffield / lazygit
simple terminal UI for git commands
A simple terminal UI for git commands
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. 💙
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…
alias lazygit=lazygit
that's totally unnecessaryThat's actually pretty cool! I'm going to apopt that.
I've been creating scripts lately to ease my development, and amazingly I've never thought about this, is dead simple and useful.
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.
Love this. Do you mind if I share it in next week’s bash tip? I’ll of course link to your great article
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