1
00:00:00,876 --> 00:00:02,466
- [Narrator] Hi and
welcome back to the course.

2
00:00:02,466 --> 00:00:05,271
In this video, we're going
to get our code into GitHub.

3
00:00:05,271 --> 00:00:07,682
Because we have to do
that before we can deploy

4
00:00:07,682 --> 00:00:09,315
it to Heroku.

5
00:00:09,315 --> 00:00:11,922
Heroku is going to read
the code from GitHub and

6
00:00:11,922 --> 00:00:13,681
deploy it to make it available.

7
00:00:13,681 --> 00:00:16,046
So we have to get it to GitHub first.

8
00:00:16,046 --> 00:00:17,643
So let's do that.

9
00:00:17,643 --> 00:00:20,825
What I've done is created a new folder

10
00:00:20,825 --> 00:00:22,827
for this section's code.

11
00:00:22,827 --> 00:00:26,160
I have copied the code from section six.

12
00:00:27,112 --> 00:00:28,210
Remember that?

13
00:00:28,210 --> 00:00:32,006
Our API that has items, stores and users

14
00:00:32,006 --> 00:00:34,006
in models and resources.

15
00:00:35,070 --> 00:00:36,986
So a fairly simple API to get started.

16
00:00:36,986 --> 00:00:40,186
And then in the final
end of course project,

17
00:00:40,186 --> 00:00:43,595
which is gonna be a larger
project, we're also work

18
00:00:43,595 --> 00:00:46,245
with Heroku and deploy there too.

19
00:00:46,245 --> 00:00:48,169
But that's going to be
at the end of the course.

20
00:00:48,169 --> 00:00:50,573
For now let's use the code
in section six just to

21
00:00:50,573 --> 00:00:53,073
learn how to deploy to Heroku.

22
00:00:53,969 --> 00:00:57,195
So I've copied the code and
I'm gonna have a wee look here.

23
00:00:57,195 --> 00:01:01,981
As you can see I've got
app.py, db.py and security.py.

24
00:01:01,981 --> 00:01:03,835
And then we've got the
models folder which has

25
00:01:03,835 --> 00:01:06,020
the item, store and user.

26
00:01:06,020 --> 00:01:07,826
And the resources folder which has

27
00:01:07,826 --> 00:01:10,026
item, store and user as too.

28
00:01:10,026 --> 00:01:12,859
And they both have an __init__.py.

29
00:01:14,730 --> 00:01:18,196
Now there's a couple of things
I'm going to add as well.

30
00:01:18,196 --> 00:01:21,946
And the first one is
going to be a .gitignore

31
00:01:24,041 --> 00:01:28,275
So what I'm going to do is
open atom in this folder.

32
00:01:28,275 --> 00:01:30,595
And it has appeared on the other screen.

33
00:01:30,595 --> 00:01:31,627
There we go.

34
00:01:31,627 --> 00:01:33,505
So here we have atom.

35
00:01:33,505 --> 00:01:37,792
The first thing we're going
to do is create a new file and

36
00:01:37,792 --> 00:01:39,375
call it .gitignore.

37
00:01:41,439 --> 00:01:45,950
The contents of this file
are patterns which are going

38
00:01:45,950 --> 00:01:49,575
to be ignored when it comes
to adding them to Git.

39
00:01:49,575 --> 00:01:51,913
So what are some things
that we'll want to ignore

40
00:01:51,913 --> 00:01:54,092
when we add files to Git.

41
00:01:54,092 --> 00:01:57,627
What are some things that we
don't want to put into Git?

42
00:01:57,627 --> 00:02:01,306
Well, for example, something
we may not want to put into Git

43
00:02:01,306 --> 00:02:02,806
is this .DS_Store.

44
00:02:04,821 --> 00:02:06,659
This is something that the Mac adds

45
00:02:06,659 --> 00:02:08,859
to every folder we access.

46
00:02:08,859 --> 00:02:10,612
And we don't want that in Git.

47
00:02:10,612 --> 00:02:13,029
So let's put .DS_Store there.

48
00:02:15,463 --> 00:02:19,186
Another thing we may not
want in our Git repository

49
00:02:19,186 --> 00:02:21,436
is any __pycache__ folders.

50
00:02:24,169 --> 00:02:28,332
The pycache folders are
essentially just caches of the

51
00:02:28,332 --> 00:02:31,683
compiled versions of Python code.

52
00:02:31,683 --> 00:02:34,830
Not very necessary whenever
we run the Python code

53
00:02:34,830 --> 00:02:36,510
these will get created as well.

54
00:02:36,510 --> 00:02:37,982
So it doesn't make sense to put them

55
00:02:37,982 --> 00:02:39,982
into the Git repository.

56
00:02:40,881 --> 00:02:44,612
Something else we won't want
is the compiled python code.

57
00:02:44,612 --> 00:02:45,779
So .pyc files.

58
00:02:47,743 --> 00:02:51,910
If we put *.pyc that's going
to ignore all the .pyc files.

59
00:02:57,178 --> 00:02:59,466
Okay, let's say that
this is all that we want.

60
00:02:59,466 --> 00:03:02,010
Let's go back to the terminal.

61
00:03:02,010 --> 00:03:04,593
Now we're going to do git init.

62
00:03:05,538 --> 00:03:09,705
And then, as you know,
initialises the MC Git repository.

63
00:03:12,133 --> 00:03:14,111
Now we've got the Git
repository initialised here.

64
00:03:14,111 --> 00:03:16,562
We're gonna do git status
and that's going to tell us

65
00:03:16,562 --> 00:03:19,531
what we're going to be looking at when it

66
00:03:19,531 --> 00:03:21,811
comes to adding things to Git.

67
00:03:21,811 --> 00:03:25,730
So as you can see we've got
.gitignore, app.py, db.py,

68
00:03:25,730 --> 00:03:29,981
models/, resources/ and security.py.

69
00:03:29,981 --> 00:03:34,262
If we go back to the .gitignore
and remove .DS_Store and

70
00:03:34,262 --> 00:03:37,121
then we do git status again.

71
00:03:37,121 --> 00:03:39,770
Notice how the .DS_Store
file now appears there.

72
00:03:39,770 --> 00:03:43,122
That's something we may want
to add to our staging area.

73
00:03:43,122 --> 00:03:44,425
But we don't want that.

74
00:03:44,425 --> 00:03:47,209
So let's go back and re-add .DS_Store.

75
00:03:47,209 --> 00:03:49,863
That was just to show you what happens.

76
00:03:49,863 --> 00:03:51,869
Okay, another git status reveals that

77
00:03:51,869 --> 00:03:53,221
that has now disappeared.

78
00:03:53,221 --> 00:03:55,428
And indeed this is all that we want to add

79
00:03:55,428 --> 00:03:57,059
to our git repository.

80
00:03:57,059 --> 00:04:01,226
So what we're going to do is
we're going to add everything.

81
00:04:02,158 --> 00:04:04,324
So let's look at the git status again.

82
00:04:04,324 --> 00:04:07,233
And notice how it's added
all of the files except

83
00:04:07,233 --> 00:04:08,483
the .gitignore.

84
00:04:09,980 --> 00:04:12,531
That is because the
.gitignore is what's called

85
00:04:12,531 --> 00:04:13,921
a hidden file.

86
00:04:13,921 --> 00:04:15,552
It starts with a full stop.

87
00:04:15,552 --> 00:04:19,388
End with a period so Git
doesn't add it by default.

88
00:04:19,388 --> 00:04:21,140
So we have to add that manually.

89
00:04:21,140 --> 00:04:24,161
So we're going to do git add .gitignore.

90
00:04:24,161 --> 00:04:25,791
And now git status again reveals

91
00:04:25,791 --> 00:04:27,421
that we've added all of these.

92
00:04:27,421 --> 00:04:30,321
And Git treats them all as new files.

93
00:04:30,321 --> 00:04:32,731
Even though we know they're not brand new.

94
00:04:32,731 --> 00:04:35,666
But this is the first time that
Git knows about these files.

95
00:04:35,666 --> 00:04:38,412
So it's calling them new files.

96
00:04:38,412 --> 00:04:40,441
The next time when we make
a change to one of these

97
00:04:40,441 --> 00:04:44,808
files it will say modified
as opposed to new file.

98
00:04:44,808 --> 00:04:46,153
Okay, not that we've got all of this

99
00:04:46,153 --> 00:04:48,868
we're gonna do a git commit.

100
00:04:48,868 --> 00:04:51,784
And because we've already
added all of the files.

101
00:04:51,784 --> 00:04:54,318
Git is going to know that
when we commit we want to

102
00:04:54,318 --> 00:04:57,136
put all of these files
into a new snapshot.

103
00:04:57,136 --> 00:04:58,219
A new commit.

104
00:04:59,546 --> 00:05:02,197
- M allows us to write a short message.

105
00:05:02,197 --> 00:05:06,071
And we're going to write
something like "Added"

106
00:05:06,071 --> 00:05:08,738
or something like "First commit,

107
00:05:09,904 --> 00:05:12,304
added REST API to access

108
00:05:12,304 --> 00:05:15,721
items, stores, and user authentication.".

109
00:05:19,013 --> 00:05:21,275
You'd want your commit
messages to have some sort of

110
00:05:21,275 --> 00:05:23,889
information as to what is in the code.

111
00:05:23,889 --> 00:05:26,507
Just so when you go back
and look through the commit

112
00:05:26,507 --> 00:05:29,924
history, you can see what was added when.

113
00:05:31,172 --> 00:05:33,111
So now we've added that commit.

114
00:05:33,111 --> 00:05:34,908
And as you can see it tells
us that it's created all

115
00:05:34,908 --> 00:05:36,952
these files and all is good.

116
00:05:36,952 --> 00:05:39,585
We've added 256 lines of code.

117
00:05:39,585 --> 00:05:43,744
That is the 256 insertions
which is quite nice.

118
00:05:43,744 --> 00:05:47,911
Okay, and now we have to
add the remote repository.

119
00:05:49,878 --> 00:05:53,644
So "git remote add origin"
and here should go the address

120
00:05:53,644 --> 00:05:55,519
of your Git repository.

121
00:05:55,519 --> 00:05:58,655
So if you don't have one,
go ahead and create a public

122
00:05:58,655 --> 00:06:01,322
git repository for this project.

123
00:06:07,835 --> 00:06:10,918
Okay, so we're gonna do that as well.

124
00:06:12,196 --> 00:06:15,052
I'm gonna paste in the
address of the repository

125
00:06:15,052 --> 00:06:16,552
I've just created.

126
00:06:18,118 --> 00:06:20,610
And then we're going to do git push.

127
00:06:20,610 --> 00:06:24,365
And then we have to tell
it what we want to push.

128
00:06:24,365 --> 00:06:26,369
We're going to push the master branch

129
00:06:26,369 --> 00:06:28,452
to the origin repository.

130
00:06:31,010 --> 00:06:33,584
So we do git push -u origin master.

131
00:06:33,584 --> 00:06:35,178
And that's gonna push the master branch.

132
00:06:35,178 --> 00:06:36,856
Which is the branch we're currently on.

133
00:06:36,856 --> 00:06:39,683
It's the default branch
into the origin remote

134
00:06:39,683 --> 00:06:41,516
that we've just added.

135
00:06:42,822 --> 00:06:45,237
Now it may ask you for your
password or in my case since

136
00:06:45,237 --> 00:06:47,885
I've got the SSH key
already added it doesn't ask

137
00:06:47,885 --> 00:06:48,968
for anything.

138
00:06:51,122 --> 00:06:53,246
Okay and that is this that has been added.

139
00:06:53,246 --> 00:06:58,209
Let's go over to GitHub and
verify that everything is there.

140
00:06:58,209 --> 00:07:01,921
And indeed here we are
we've just added the code.

141
00:07:01,921 --> 00:07:04,988
Here you can see in the remote repository

142
00:07:04,988 --> 00:07:07,898
here in GitHub this has been added.

143
00:07:07,898 --> 00:07:10,681
This is going to be public
so you can also use this

144
00:07:10,681 --> 00:07:13,456
repository if you prefer
instead of creating your own.

145
00:07:13,456 --> 00:07:15,919
That's perfectly fine as well.

146
00:07:15,919 --> 00:07:20,584
If you want to get your own
version of this repository.

147
00:07:20,584 --> 00:07:24,751
You can go into the repository
page and then press fork.

148
00:07:25,940 --> 00:07:28,321
That is going to essentially
copy the entire repository

149
00:07:28,321 --> 00:07:31,056
but put it into your account.

150
00:07:31,056 --> 00:07:32,896
Then you can make changes
to it without affecting the

151
00:07:32,896 --> 00:07:34,579
original repository.

152
00:07:34,579 --> 00:07:38,629
And you can deploy it
to Heroku and the sort.

153
00:07:38,629 --> 00:07:43,234
Okay so now that this is
here in GitHub we can put it

154
00:07:43,234 --> 00:07:44,234
into Heroku.

155
00:07:45,068 --> 00:07:47,389
So I'll see you in the very next video.

