Skip to content

Instantly share code, notes, and snippets.

@daneden
Created March 21, 2020 16:10
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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