Skip to content

Instantly share code, notes, and snippets.

@flaxel
Last active May 14, 2024 16:25
Show Gist options
  • Save flaxel/fc9f8f721765fb4c41d1db7ccc1b5148 to your computer and use it in GitHub Desktop.
Save flaxel/fc9f8f721765fb4c41d1db7ccc1b5148 to your computer and use it in GitHub Desktop.

Revisions

  1. flaxel revised this gist Oct 19, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion update_git.sh
    Original file line number Diff line number Diff line change
    @@ -24,7 +24,7 @@ update(){
    current_branch=$(git rev-parse --abbrev-ref HEAD)

    # update branch repository
    [ $current_branch = "master" ] && git pull --ff-only --all -p || git pull --ff-only origin $current_branch
    [[ $current_branch =~ ^(master|main)$ ]] && git pull --ff-only --all -p || git pull --ff-only origin $current_branch

    # cleanup local branches
    git branch --merged | egrep -v "(^\*|master|main)" | xargs git branch -D
  2. flaxel revised this gist Oct 14, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion update_git.sh
    Original file line number Diff line number Diff line change
    @@ -27,7 +27,7 @@ update(){
    [ $current_branch = "master" ] && git pull --ff-only --all -p || git pull --ff-only origin $current_branch

    # cleanup local branches
    git branch --merged | egrep -v "(^\*|master|main)" | xargs git branch -d
    git branch --merged | egrep -v "(^\*|master|main)" | xargs git branch -D
    }

    # check necessary installations
  3. flaxel revised this gist Sep 22, 2020. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions update_git.sh
    Original file line number Diff line number Diff line change
    @@ -25,6 +25,9 @@ update(){

    # update branch repository
    [ $current_branch = "master" ] && git pull --ff-only --all -p || git pull --ff-only origin $current_branch

    # cleanup local branches
    git branch --merged | egrep -v "(^\*|master|main)" | xargs git branch -d
    }

    # check necessary installations
  4. flaxel revised this gist Jun 10, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion update_git.sh
    100644 → 100755
    Original file line number Diff line number Diff line change
    @@ -24,7 +24,7 @@ update(){
    current_branch=$(git rev-parse --abbrev-ref HEAD)

    # update branch repository
    [ $current_branch = "master" ] && git pull --ff-only --all -p || git pull origin $current_branch
    [ $current_branch = "master" ] && git pull --ff-only --all -p || git pull --ff-only origin $current_branch
    }

    # check necessary installations
  5. flaxel created this gist Jun 3, 2020.
    44 changes: 44 additions & 0 deletions update_git.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,44 @@
    #!/bin/sh

    # check if console program is installed
    check_installation(){
    type $1 >/dev/null 2>&1 || { echo >&2 "$1 is required: $2 Aborting."; exit 1; }
    }

    # printing usage information
    usage(){
    echo "This program is used to update all git repositories in the given folder."
    echo "Usage: $0 <folder>"
    exit 1
    }

    # update a git repository
    update(){
    # printing action
    echo "\nUpdating $1 ..."

    # change directory to repository
    cd "$1"

    # get current branch
    current_branch=$(git rev-parse --abbrev-ref HEAD)

    # update branch repository
    [ $current_branch = "master" ] && git pull --ff-only --all -p || git pull origin $current_branch
    }

    # check necessary installations
    check_installation "git" "Please download git from https://git-scm.com/downloads."
    check_installation "realpath" "Please install realpath with 'sudo apt install realpath' or 'brew install coreutils'."

    # check if arguments passed
    [ $# -eq 0 ] && usage

    # printing action
    echo "Update all git repositories..."

    # absolute origin folder
    folder=$(realpath $1)

    # update repositories with .git folder
    for git_folder in $(find $folder -name '.git'); do update $(dirname "$git_folder"); done