Re:Scripts I wrote that I use all the time
by marcuskaz on Wednesday October 22, 2025 @10:40PM
(#45677600)
Likewise, why doesn't git clone automatically cd into the repo?
[ Parent
| on HN ]
Re:Scripts I wrote that I use all the time
by andriamanitra on Thursday October 23, 2025 @10:07AM
(#45681974)
A subprocess (git) can't modify the working directory of the parent process (the shell). This is a common annoyance with file managers like yazi and ranger as well—you need an extra (usually manual!) installation step to add a shell integration for whichever shell you're using so the shell itself can change directory.
The best solution for automatically cd'ing into the repo is to wrap git clone in a shell function or alias. Unfortunately I don't think there's any way to make git clone print the path a repository was cloned to, so I had to do some hacky string processing that tries to handle the most common usage (ignore the "gh:" in the URL regex, my git config just expands it to "[email protected]:"):
https://github.com/Andriamanitra/dotfiles/blob/d1aecb8c37f09...