- Add .config/git/config + Define aliases + Configure default behavior in various situations + Add user information with signing key - Add .config/git/commit_msg_template.txt - Add .config/git/ignore - Integrate `git` aliases into the shell
35 lines
722 B
Shell
Executable file
35 lines
722 B
Shell
Executable file
#!/bin/sh
|
|
|
|
# Make all local branches match the remote branch they track,
|
|
# discarding local-only commits and, on the current branch,
|
|
# uncommitted changes as well
|
|
#
|
|
# Branches without an upstream are left alone
|
|
#
|
|
# Usage: git match-remote
|
|
|
|
set -eu
|
|
|
|
|
|
git fetch --all --prune
|
|
|
|
|
|
current="$(git branch --show-current)"
|
|
|
|
|
|
git for-each-ref --format='%(refname:short) %(upstream:short)' refs/heads/ |
|
|
while read -r branch upstream; do
|
|
|
|
[ -n "$upstream" ] || continue
|
|
|
|
git rev-parse --verify --quiet "$upstream" >/dev/null || continue
|
|
|
|
if [ "$branch" = "$current" ]; then
|
|
git reset --hard "$upstream"
|
|
continue
|
|
fi
|
|
|
|
git branch -f "$branch" "$upstream"
|
|
echo "Moved $branch to $upstream"
|
|
|
|
done
|