Skip to content

Instantly share code, notes, and snippets.

@noeldiaz
Created September 21, 2016 02:16
Show Gist options
  • Save noeldiaz/075ba3af7acfde333a687b1d71ff0dcf to your computer and use it in GitHub Desktop.
Save noeldiaz/075ba3af7acfde333a687b1d71ff0dcf to your computer and use it in GitHub Desktop.
Clone repository and cd into the directory

Installation

You can add the gcd script to your local bin path or you can add the followin snippet to your bash .profile or zsh .zshrc file.

function gcd {
  REPO=$1
  CLONEPATH=$2

  if [ -z $CLONEPATH ]; then
      CLONEPATH=${$(basename $1)/.git/}
  fi

  git clone $REPO $CLONEPATH
  cd $CLONEPATH
}

Usage

gcd https://github.com/laravel/laravel.git
(git clone https://github.com/laravel/laravel.git && cd laravel)

gcd https://github.com/laravel/laravel.git phpthebestway
(git clone https://github.com/laravel/laravel.git phpthebestway && cd phpthebestway)

#!/bin/bash
REPO=$1
CLONEPATH=$2
if [ -z $CLONEPATH ]; then
CLONEPATH=${$(basename $1)/.git/}
fi
git clone $REPO $CLONEPATH
cd $CLONEPATH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment