1

I'm trying to put a wrapper on the git clone command. In other words when I type the command "git clone user@server:group/repo.git" the git clone command would trigger a script and inside the script it would... 1. Clone the git repository 2. run the command "git init" on the repository

The reason I want to do this is because I want the clone projectors set up a certain way automatically.

tyleax
  • 1,556
  • 2
  • 17
  • 45

1 Answers1

2

Alias the desired command:

alias git='mygit' 

create a script mygit:

#/bin/bash

if [ "$1" == "clone" ] ; then
  # do your stuff here
  echo special behavior of git clone
else
  command git "$@"
fi

Save it somewhere the PATH variable is set to, e. g. /home/user/bin. chmod 0770 it to make it executable.

When you type git clone in the shell you will fire up your special stuff. If you type e. g. git push the script will call the original git program.

cmks
  • 527
  • 2
  • 11
  • 1
    Instead of `which git`, use `command git` to bypass the alias. That's built in to the shell (at least sh and bash both, I am much less sure about dash, zsh, and other shells). Then, use `"$@"` to avoid altering any user-supplied quoting (using `$*` causes re-interpretation of white space as defined by `$IFS`). – torek Mar 28 '17 at 22:09
  • @torek thank you for these hints. – cmks Mar 28 '17 at 22:18