-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgit-sync
More file actions
executable file
·29 lines (23 loc) · 840 Bytes
/
git-sync
File metadata and controls
executable file
·29 lines (23 loc) · 840 Bytes
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
#!/bin/bash
#
# Sync the current branch: pull from upstream and push to fork
#
# $1 = upstream (defaults to `git hub-remotes --upstream`)
# $2 = fork (defaults to `git hub-remotes --fork`)
# $3 = branch (defaults to the current branch)
set -e # stop on error
SCRIPTS="$(dirname "$0")"
upstream=${1:-$("$SCRIPTS"/git-remotes --upstream | cut -f1)}
fork=${2:-$("$SCRIPTS"/git-remotes --fork | cut -f1)}
current=$(git symbolic-ref --short HEAD)
branch=${3:-$current}
echo "Pulling latest commits from $upstream/$branch to $current..."
echo "> git pull --prune --tags $upstream $branch"
git pull --prune --tags $upstream $branch
echo "Done."
if [[ "$upstream" != "$fork" ]]; then
echo "Pushing $current to $fork/$branch..."
echo "> git push --prune $fork $current:$branch"
git push --prune $fork $current:$branch
echo "Done."
fi