Skip to content

Instantly share code, notes, and snippets.

@nottrobin
Last active September 4, 2015 13:22
Show Gist options
  • Save nottrobin/838cab01538742629db6 to your computer and use it in GitHub Desktop.
Save nottrobin/838cab01538742629db6 to your computer and use it in GitHub Desktop.
helper function for updating a directory path with a git project
function update_git_dir {
# Update a git dir, either by cloning it or pulling changes down
# Usage:
# update_git_dir ${branch} ${git_url} ${dir_path}
branch=$1
git_url=$2
dir_path=$3
git clone --depth 1 -b ${branch} ${git_url} ${dir_path} || (
git -C ${dir_path} clean -fd
git -C ${dir_path} remote set-url origin ${git_url}
git -C ${dir_path} fetch origin
git -C ${dir_path} checkout ${branch}
git -C ${dir_path} reset --hard origin/${branch}
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment