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