]> git.phdru.name Git - git-scripts.git/blob - fork
Feat(fix-detached-head): Replace `branch -r` by `for-each-ref`
[git-scripts.git] / fork
1 #! /bin/sh
2
3 if [ -z "$2" -o -n "$4" ]; then
4    echo "Usage: $0 upstream origin [local]" >&2
5    exit 1
6 fi
7
8 upstream="$1"
9 origin="$2"
10 local_repo="$3"
11 test -z "$local_repo" && local_repo="`basename \"$origin\" .git`"
12
13 if [ -d "$local_repo"/.git ]; then
14    cd "$local_repo"
15 fi &&
16
17 if [ -d .git ]; then
18    git remote add upstream "$upstream"
19    git remote set-url origin "$origin" || git remote add origin "$origin"
20 else
21    git clone -o upstream "$upstream" "$local_repo" &&
22    cd "$local_repo" &&
23    chmod a-x .git/config &&
24    git remote add origin "$origin"
25 fi &&
26
27 "`dirname \"$0\"`"/set-commit-date-recursive &&
28 pwd >> "`dirname \"$0\"`"/locate-all.list &&
29 branch="`git rev-parse --abbrev-ref HEAD`" &&
30
31 git pull upstream $branch &&
32 git pull origin $branch &&
33 git push -u origin $branch &&
34
35 git config branch.$branch.remote upstream &&
36 git config branch.$branch.remotepush origin &&
37 git config branch.$branch.merge refs/heads/$branch &&
38 git config push.default current &&
39
40 exec git gc --aggressive