VOOZH about

URL: https://www.javacodegeeks.com/2018/04/custom-git-subcommands.html

⇱ Custom Git subcommands - Java Code Geeks


Heavy users of Git often find themselves writing their own Git shortcuts or scripts which combine multiple Git commands for frequently used features. The possibilities to shortcut your way around Git include Git aliases, shell aliases, or custom scripts that reside in your $PATH.

For the latter, there is an interesting feature in the Git command line that I just recently discovered: Git automatically resolved subcommands from executables in the PATH that follow the naming convention git-<subcmd>. These subcommands can be executed with git <subcmd>.

For my own projects, I wrote a script git-update which does a commit on all files with default or custom message, rebase-pull, and push:

#!/bin/zsh
set -eu

message=${1:-updated}
branch=$(git symbolic-ref -q HEAD | sed -e 's|^refs/heads/||')

pushd $(git rev-parse --show-toplevel || echo ".")
 git add --all .
 git commit -m "${message}" || true
 git pull --rebase origin ${branch} || true
 git push origin ${branch}
popd

The executable file git-update resides in my $PATH and can be called with $> git update [commit-message]. No other configuration was required.

Published on Java Code Geeks with permission by Sebastian Daschner, partner at our JCG program. See the original article here: Custom Git subcommands

Opinions expressed by Java Code Geeks contributors are their own.

Do you want to know how to develop your skillset to become a Java Rockstar?
Subscribe to our newsletter to start Rocking right now!
To get you started we give you our best selling eBooks for FREE!
1. JPA Mini Book
2. JVM Troubleshooting Guide
3. JUnit Tutorial for Unit Testing
4. Java Annotations Tutorial
5. Java Interview Questions
6. Spring Interview Questions
7. Android UI Design
and many more ....
I agree to the Terms and Privacy Policy

Thank you!

We will contact you soon.

Tags
Git
👁 Photo of Sebastian Daschner
Sebastian Daschner
April 20th, 2018Last Updated: April 20th, 2018
0 108 1 minute read

Sebastian Daschner

Sebastian Daschner is a self-employed Java consultant and trainer. He is the author of the book 'Architecting Modern Java EE Applications'. Sebastian is a Java Champion, Oracle Developer Champion and JavaOne Rockstar.
Subscribe

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Oldest
Newest Most Voted
Back to top button
Close
wpDiscuz