-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit-sync
More file actions
executable file
·38 lines (32 loc) · 1.04 KB
/
git-sync
File metadata and controls
executable file
·38 lines (32 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env bash
# /// dotfiles
# description = "Sync all branches and tags on all remotes (fetch + ff-only merge + push)."
# author = "goncalomb"
# year = "2026"
# tags = ["stable"]
# ///
set -euo pipefail
echo "Syncing all branches and tags on all remotes..."
sleep 2
# fetch from all remotes
git fetch --all
# update (ff-only) local branches from remotes (will fail if diverged)
BRANCH_C=$(git rev-parse --abbrev-ref HEAD)
for BRANCH in $(git branch --format='%(refname:short)'); do
for REMOTE in $(git remote); do
if git merge-base --is-ancestor "$REMOTE/$BRANCH" "$BRANCH"; then
: # already up to date
elif [[ "$BRANCH" == "$BRANCH_C" ]]; then
# current branch, normal ff-only merge
git merge --ff-only "$REMOTE/$BRANCH"
else
# hack for other branches (also fails if diverged)
git fetch . "$REMOTE/$BRANCH:$BRANCH"
fi
done
done
# push to all remotes
for REMOTE in $(git remote); do
git push --all "$REMOTE"
git push --tags "$REMOTE"
done