2

Ok, let me clarify what I mean. I'm writing a few shell scripts for some special use cases working with git. Long story as to why.

Anyway, I could call them all as separate scripts, but I think it would be beautiful and elegant if I could basically make them new git commands. I would have my own version of the "git" file, which would be a bash script that would check the first argument. If the first argument wasn't one of a few, select options, it would call the regular git instead.

I know, this might be a bit crazy, and it might not even be possible, but I'm just curious.

My machine's path has /home/me/bin as the first entry, yet putting a file called git there doesn't seem to override the behavior. Maybe restarting my computer will fix this?

Anyway, just looking for advice. Feel free to say "no, this can't be done", and if so I'll just move on.

Edit: Nevermind. Just needed to reboot. Have a simple "Hello World!" going on to see if I can override the command. It's working. Happy times.

3
  • Make a bash alias? Commented May 16, 2016 at 18:19
  • 1
    thediscoblog.com/blog/2014/03/29/custom-git-commands-in-3-steps Commented May 16, 2016 at 18:19
  • git aliases can only do one command line you can string commands together, Commented May 16, 2016 at 18:33

2 Answers 2

1

You are not crazy. What you want to do is make a git alias.

https://git.wiki.kernel.org/index.php/Aliases#Aliases

https://stackoverflow.com/a/2553799/6194839

Sign up to request clarification or add additional context in comments.

Comments

1

Yes, it's possible.

Modifying existing Git commands is possible, but not elegant. You have to create a 'git' script, and you can run into many issues.

Creating new Git command is easy, just put the script into your $PATH, like ~/bin/git-related (it will create a new 'git related' command).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.