forked from mk12/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit-master-to-main.sh
More file actions
executable file
·35 lines (28 loc) · 888 Bytes
/
git-master-to-main.sh
File metadata and controls
executable file
·35 lines (28 loc) · 888 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
30
31
32
33
34
35
#!/bin/bash
set -Eeufo pipefail
trap 'echo >&2 "$0:$LINENO [$?]: $BASH_COMMAND"' ERR
die() {
echo "$*" >&2
exit 1
}
step() {
echo "> $*"
"$@"
}
[[ -d .git ]] || die "not in a git repo"
echo -n "Copy token from https://github.com/settings/tokens/new with repo permissions: "
read -r token
[[ -n "$token" ]] || die "token is empty"
user=mk12
repo=$(basename "$(pwd)")
git remote -v | grep -F "git@github.com:$user/$repo" || die "not on github"
step git branch -m master main
step git push -u origin main
step git symbolic-ref refs/remotes/origin/HEAD refs/remotes/origin/main
step curl --fail -X PATCH \
-u "$user:$token" \
-H 'Content-Type: application/json' \
-H "Accept: application/vnd.github.v3+json" \
-d "{\"name\": \"$repo\", \"default_branch\": \"main\"}" \
"https://api.github.com/repos/$user/$repo"
step git push origin --delete master