]> ruderich.org/simon Gitweb - config/dotfiles.git/blob - bin/git-update.sh
bin/git-update.sh: Add --local option.
[config/dotfiles.git] / bin / git-update.sh
1 #!/bin/sh
2
3 # Push current commits to all remotes and fetch from all remotes. Then display
4 # unmerged commits and changes in the repositories.
5 #
6 # If --local is given as option, no fetching/pushing is performed.
7 #
8 # If an argument is given cd to this directory before running the commands.
9 #
10 # Very useful to sync multiple remotes.
11
12
13 LOCAL=
14 if [ x$1 = x--local ];then
15     LOCAL=1
16     shift
17 fi
18
19 if [ x$1 != x ]; then
20     echo $1
21     cd "$1"
22 fi
23
24 if [ x$LOCAL = x ]; then
25     # Get all remote changes.
26     git remote update 2>&1 | grep -v Fetching
27     # Push all local changes to remote(s).
28     for remote in `git remote`; do
29         git push $remote 2>&1 | grep -v 'Everything up-to-date'
30     done
31 fi
32 # Show unmerged changes.
33 git branch -rv --color --no-merged
34 # Show uncommitted changes.
35 if `echo "$1" | grep '\.git\$' > /dev/null`; then
36     cd ..
37 fi
38 git status | grep 'Changes to be committed:' > /dev/null \
39     && echo '-> modified (staged)'
40 git status | grep 'Changed but not updated:' > /dev/null \
41     && echo '-> modified'
42 git status | grep 'Untracked files:' > /dev/null \
43     && echo '-> modified (untracked)'
44
45 echo