DEV Community

Cover image for Improve Your Git Productivity with Bash

Improve Your Git Productivity with Bash

Dale Nguyen on October 16, 2019

There are a few methods that you can work with Git. You can either use some user-friendly software like SourceTree to manage your workflow and repo...
Collapse
 
alexparra profile image
Alex Parra

I have lots of git aliases... some in git config and others in bash_profile.
The one I find the most useful is for checking diff of commits between two branches.

But regarding your first alias, I’d like to raise attention that you should review what you’re committing and an alias as you’ve described may prevent less experienced developers from reviewing changes before committing.

There’s another problem with aliases... when you have to work on a machine that’s not yours, you won’t know how... unless you configure your aliases.

I’m not against aliases, I have some myself.
Just sharing concerns for others to see and consider.
Best.

Collapse
 
oscherler profile image
Olivier “Ölbaum” Scherler

I always use git add -p when I want to commit. It will go through each chunk of changes and ask if I want to add it or not. It’s a great way to review what you are going to commit, spot and skip some leftover debugging code, and it allows you to make smaller commits at the same time.

You can even edit the patch before adding it, which is daunting at first but can be quite convenient to quickly omit a leftover print statement in the middle of an otherwise valid change.

Collapse
 
dalenguyen profile image
Dale Nguyen

Thanks for your concern. I agree that we should check the differences before committing. This step is done after we check everything. We can do it in the editor like VSCode or through the alias: gs and gd.

Collapse
 
rahul0705 profile image
Rahul Mohandas

Seems to me your looking for git commit -am <message> but I caution, the reason most of these commands are separate is because you should be aware of what your commiting, all to often junior engineers use got as a remote backup of their hard drive and while there is some more truth to that; users should be aware of what they are adding and WHY (that's the point of the message).

Collapse
 
santaxxl profile image
Dominik Mańkowski • Edited

git commit -am <msg> is different from git add . && git commit -m <msg>. The former does not add newly created files to the index.

Collapse
 
jeklah profile image
Jeklah

You can do this in any shell, not just bash.

Collapse
 
taikedz profile image
Tai Kedzierski

I've been maintaining something like this for a while now... I use it every day...! :-D

It adds and commits in one go, warns me of committing on master, shows the log graph easily, manages commit profiles (rudimentary) and plenty more. I might admittedly have gone overboard.

The only catch is that because of the dependency on bash-builder, it only runs properly on Ubuntu/Debian. No guarantees elsewhere until I rewrite bash-builder distro-agnostically...

Collapse
 
dalenguyen profile image
Dale Nguyen

Nice work, Tai! As long as it is useful, somebody will like it too.

Collapse
 
katnel20 profile image
Katie Nelson

Using the gp alias, I'd be confused on whether I was doing a pull or a push.

Collapse
 
dalenguyen profile image
Dale Nguyen

Git push is not that easy compared to Git pull, so gp is only for Git pull. You will remember after using it for few times.

Collapse
 
dalenguyen profile image
Dale Nguyen

Nice, I'm not the only one who hates repetition :D