]> ruderich.org/simon Gitweb - config/dotfiles.git/blob - bin/git-update.sh
de71bec0dc304c78b3041bd13ae85228642f05a1
[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         git push --tags $remote 2>&1 | grep -v 'Everything up-to-date'
31     done
32 fi
33 # Show unmerged changes.
34 git branch -rv --color --no-merged
35 # Show uncommitted changes.
36 if `echo "$1" | grep '\.git\$' > /dev/null`; then
37     cd ..
38 fi
39 git status | grep 'Changes to be committed:' > /dev/null \
40     && echo '-> modified (staged)'
41 git status | grep 'Changed but not updated:' > /dev/null \
42     && echo '-> modified'
43 git status | grep 'Untracked files:' > /dev/null \
44     && echo '-> modified (untracked)'
45
46 echo