I wanted to add a Git alias that does a
git clone and then
cd to change into the new directory. However, while the
git clone worked fine, the directory change did not. It turns out you can NOT change directories from within a Git alias.
Why Can’t You Change Directories from a Git Alias
A Git alias is run inside a subshell (not your existing shell you are working in) and therefore when you change directories, you are changing them in the subshell. When the subshell finishes and terminates, regardless of any directory changes you applied to the subshell, the shell you are working in remains unchanged.
Since we can not change the directory from a Git alias, we are better using a shell alias. i.e. instead of
git ccd email@example.com:salcode/salcode-git.git
we’ll run something like
I’ve opened an issue, Issue 53: Add git clone and cd into directory alias on my zsh configuration repository to add this.