craigmiller160
craigmiller160

Reputation: 6273

Is it possible to overwrite git command with my own version?

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.

Upvotes: 2

Views: 251

Answers (2)

FelipeC
FelipeC

Reputation: 9488

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).

Upvotes: 1

Bryce Drew
Bryce Drew

Reputation: 6729

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

Upvotes: 1

Related Questions