CD into a cloned Git repository
Regularly I clone down repositories into a directory and then have to manually pluck the repository name out of the clone URL to cd
into the cloned directory.
I found the following snippet which will extract the repository name out of the clone url and cd
into it.
1# ~/.zshrc/.bashrc/whatever...
2alias cdr='cd $(basename $_ .git)'
This can then be used as…
1~ git clone my-repository-url
2~ cdr
3~/my-repository
Or even better…
1# ~/.zshrc/.bashrc/whatever...
2function git() {
3 if [ $1 = "clone" ]
4 then
5 command git $@ && cd "$(basename "$_" .git)"
6 else
7 command git $@
8 fi
9}