Last active
September 4, 2015 13:22
-
-
Save nottrobin/838cab01538742629db6 to your computer and use it in GitHub Desktop.
helper function for updating a directory path with a git project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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