Skip to content

Instantly share code, notes, and snippets.

@daneden
Created March 21, 2020 16:10
Show Gist options
  • Save daneden/06b8b691c1920ddf3bf3578c8ec91f00 to your computer and use it in GitHub Desktop.
Save daneden/06b8b691c1920ddf3bf3578c8ec91f00 to your computer and use it in GitHub Desktop.

git clone and cd function

A simple little alias function that lets you clone and cd into a GitHub repo in one command.

Installation

Add to your zsh or bash config (usually ~/.bash_profile or ~/.zshrc) and open a new terminal to be able to use the function.

Usage

gcd [github_repo_owner/repo_name]

# For example, the following with clone daneden/zeitgeist and `cd` into it:
gcd daneden/zeitgeist
function __gcd {
if [ "$1x" != "x" ]; then
git clone "https://github.com/$1"
DIRNAME="$(cut -d'/' -f2 <<<$1)"
cd "$DIRNAME"
fi
}
alias gcd='__gcd'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment