-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateRemoteGitDir
More file actions
executable file
·154 lines (110 loc) · 3.92 KB
/
createRemoteGitDir
File metadata and controls
executable file
·154 lines (110 loc) · 3.92 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!/bin/bash
#Just a simple bash script to facilitate remote git directory creation from a local directory
{
echo "enter github or bitbucket:"
read githubOrBitbucket
if [ $githubOrBitbucket = "github" ]
then
echo "GitHub Selected"
fi
if [ $githubOrBitbucket = "bitbucket" ]
then
echo "BitBucket Selected"
fi
echo "enter a valid git username:"
read username
#only used in bitbucket dir creation cURL command
echo "enter a valid git password:"
read -s password
echo "enter a valid project name: (as in 'MyProject')"
read projectname
echo "enter valid path to our project directory: (as in '~/Myproject')"
read projectdir
#cannot cd into dir since we're in a subshell, so pretend we are typing at the terminal: $ eval cd "~/..."
eval cd "$projectdir"
rm -rf .git/
pwd
echo "enter commit message:"
read commitmessage
echo "Start - Creating remote Git Directory named '$projectname'"
echo "Initializing Repo $projectname locally"
git init
echo "Add all files of the directory we are to Repo"
git add *
git status
echo "Commit any changes to Repo"
git commit -m "$commitmessage"
git status
echo "Create Repo $projectname on the remote server"
if [ $githubOrBitbucket = "github" ]
then
curl -u "$username" https://api.github.com/user/repos -d '{"name":"'$projectname'"}'
fi
if [ $githubOrBitbucket = "bitbucket" ]
then
echo "CURLING $password"
curl --user $username:$password https://api.bitbucket.org/1.0/repositories/ --data name=$projectname --data is_private='true'
fi
echo "Enter alias for the remote repository : (such as 'origin')"
read origin
echo "Make sure there's no alias named $origin"
git remote rm $origin
git remote -v
if [ $githubOrBitbucket = "github" ]
then
echo "Connect alias $origin to url repo: git@github.com:$username/$projectname.git"
fi
if [ $githubOrBitbucket = "bitbucket" ]
then
echo "CONNECTING.."
echo "Connect alias $origin to url repo: git@bitbucket.org:$username/$projectname.git"
fi
if [ $githubOrBitbucket = "github" ]
then
git remote add origin git@github.com:$username/$projectname.git
fi
if [ $githubOrBitbucket = "bitbucket" ]
then
echo "REMOTE ADDING.."
git remote add origin https://$username@bitbucket.org/$username/$projectname.git
fi
echo "push changes across to remote server"
git push -u origin master
if [ $githubOrBitbucket = "github" ]
then
echo "Finished - Creating remote Git Directory named 'git@github.com:$username/$projectname.git'"
fi
if [ $githubOrBitbucket = "bitbucket" ]
then
echo "Finished - Creating remote Git Directory named 'git@bitbucket.com:$username/$projectname.git'"
fi
}
# repo_name=$1
# dir_name=`basename $(pwd)`
# 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
# if [ "$invalid_credentials" == "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 git@github.com:$username/$repo_name.git > /dev/null 2>&1
# git push -u origin master > /dev/null 2>&1
# echo " done."