Monday 26 November 2018

Clone a repository with all branch using Bash Script

This bash script will cone a repository with all branch.

Create a new file git_clonerepo.sh and Put the below bash script in that file and make executable using chmod +x git_clonerepo.sh and run it

$ vim git_clonerepo.sh

#!/bin/bash
function repoclone {

        echo -n "Enter the Git repository URL : "
        read  url
        reponame=$(echo $url | awk -F/ '{print $NF}' | sed -e 's/.git$//')
        git clone $url
        cd $reponame
        for branch in $(git branch -a | grep '^\s*remotes' | egrep --invert-match '(:?HEAD|master)$'); do
            git branch --track "${branch##*/}" "$branch"
        done

}

repoclone



$ chmod +x git_clonerepo.sh

$ ./git_clonerepo.sh

No comments:

Post a Comment