• Skip to primary navigation
  • Skip to main content
Sal Ferrarello
  • About Sal Ferrarello
  • Speaking
  • Connect
    Mastodon GitHub Twitter (deprecated)
You are here: Home / Dev Tips / Git Alias Can Not Change Directory

Git Alias Can Not Change Directory

Last updated on December 1, 2023 by Sal Ferrarello

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.

Shell Alias

Since we can not change the directory from a Git alias, we are better using a shell alias. i.e. instead of

git ccd git@github.com:salcode/salcode-git.git

we’ll run something like

gccd git@github.com:salcode/salcode-git.git

I’ve opened an issue, Issue 53: Add git clone and cd into directory alias on my zsh configuration repository to add this.

Sal Ferrarello
Sal Ferrarello (@salcode)
Sal is a PHP and JavaScript developer with a focus on the WordPress platform. He is a conference speaker with a background including Piano Player, Radio DJ, Magician/Juggler, Beach Photographer, and High School Math Teacher. Sal can be found professionally at WebDevStudios, where he works as a principal engineer.

Filed Under: Computing, Dev Tips Tagged With: command line, Git, git alias, zsh

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Copyright © 2026 · Bootstrap4 Genesis on Genesis Framework · WordPress · Log in