set-gitlab-upstream 630 Bytes
Newer Older
1 2
#!/bin/sh
set -e # exit on uncaught failure
Matija Čupić's avatar
Matija Čupić committed
3
remote_name="upstream"
4

5
cd ./gitlab
6

Matija Čupić's avatar
Matija Čupić committed
7 8
if git remote | grep -q '^upstream$'; then
  echo "Remote ${remote_name} already exists in $(pwd). Exiting."
Jacob Vosmaer's avatar
Jacob Vosmaer committed
9
  exit 0
10 11
fi

Matija Čupić's avatar
Matija Čupić committed
12
git remote add "${remote_name}" "${gitlab_upstream:-https://gitlab.com/gitlab-org/gitlab-ce.git}"
Matija Čupić's avatar
Matija Čupić committed
13 14
git remote set-url --push "${remote_name}" none # make 'upstream' fetch-only
git fetch "${remote_name}" master
15 16

# check if the 'master' branch already exists
Matija Čupić's avatar
Matija Čupić committed
17
if git show-ref --verify --quiet refs/heads/master; then
Matija Čupić's avatar
Matija Čupić committed
18
  git branch --set-upstream-to="${remote_name}/master" master
19
else
Matija Čupić's avatar
Matija Čupić committed
20
  git branch master "${remote_name}/master"
21
fi