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.

0

1 Answer 1

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.

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

2 Comments

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 thank you for these hints.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.