#!/bin/bash repo_name="$1" repo_dir="../../$2" git_url="$3" branch=$4 if [ -d "$repo_dir" ];then cd $repo_dir if [ -n "$branch" ]; then cur_branch=$(git branch --show-current) echo "current branch: $cur_branch" echo "target branch: $branch" if [ "$cur_branch" != "$branch" ]; then echo "checkout to branch: $branch" git checkout $branch || true fi fi git pull --rebase || true else git clone $git_url $repo_dir if [ -n "$branch" ]; then echo "checkout to branch: $branch" git checkout $branch || true fi fi