Advertisement
Saichovsky

update-all-git-repos.sh

Oct 23rd, 2018
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.73 KB | None | 0 0
  1. #!/bin/bash
  2. # Run this script while in the directory that has all your cloned repos
  3. # The script should also be located in the same directory (together
  4. # with all your repos)
  5. test "$(pwd)" = "$(realpath $(dirname $0))" ||
  6.   (
  7.     echo "You're in the wrong directory :-(" >&2
  8.     exit 9
  9.   )
  10.  
  11. set $(ls -l | awk '/^d/ {print $NF}' | xargs)
  12.  
  13. for repo in $@; do
  14.   pushd $repo > /dev/null
  15.   IN_BRANCH=0
  16.   if [ -d $repo/.git ]; then
  17.     current_branch="$(git status | awk 'NR==1 {print $NF}')"
  18.     test "$current_branch" = "master" || IN_BRANCH=1
  19.     [ $IN_BRANCH -eq 1 ] && git checkout master > /dev/null
  20.     git pull > /dev/null && echo Repo $repo updated.
  21.     [ $IN_BRANCH -eq 1 ] && git checkout -
  22.   fi
  23.   popd > /dev/null
  24. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement