-
Notifications
You must be signed in to change notification settings - Fork 0
/
github-create
executable file
·50 lines (40 loc) · 1.35 KB
/
github-create
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/bash
repo_name=$1
dir_name=`basename $(pwd)`
invalid_credentials=0
if [ "$repo_name" = "" ]; then
echo " Repo name (hit enter to use '$dir_name')?"
read repo_name
fi
if [ "$repo_name" = "" ]; then
repo_name=$dir_name
fi
username=`git config github.user`
if [ "$username" = "" ]; then
echo " Could not find username, run 'git config --global github.user <username>'"
invalid_credentials=1
fi
token=`git config github.token`
if [ "$token" = "" ]; then
echo " Could not find token, run 'git config --global github.token <token>'"
invalid_credentials=1
fi
type=`git config github.tokentype`
if [ "$type" = "ssh" ]; then
conn_string="[email protected]:$username/$repo_name.git"
elif [ "$type" = "http" ]; then
conn_string="https://github.com/$username/$repo_name.git"
else
echo " Either token type was not enterred correctly or is empty.\n It must be one of 'ssh' or 'http'.\n Run git config --global github.tokentype <ssh|http>"
invalid_credentials=1
fi
if [ "$invalid_credentials" -eq "1" ]; then
return 1
fi
echo -n " Creating Github repository '$repo_name' ..."
curl -u "$username:$token" https://api.github.com/user/repos -d '{"name":"'$repo_name'"}' > /dev/null 2>&1
echo " done."
echo -n " Pushing local code to remote ..."
git remote add origin $conn_string > /dev/null 2>&1
git push -u origin master > /dev/null 2>&1
echo " done."