1 00:00:06,860 --> 00:00:13,185 Welcome to again, introduction to Git and GitHub. 2 00:00:13,185 --> 00:00:14,955 It's very basic. 3 00:00:14,955 --> 00:00:16,980 If you have absolutely no clue, 4 00:00:16,980 --> 00:00:18,345 then this is for you. 5 00:00:18,345 --> 00:00:20,400 Otherwise it's maybe boring. 6 00:00:20,400 --> 00:00:23,340 I'm just telling you how I'm using Git, 7 00:00:23,340 --> 00:00:24,660 and I am able to 8 00:00:24,660 --> 00:00:27,285 survive in most of the cases with that knowledge. 9 00:00:27,285 --> 00:00:29,235 Sometimes I have to 10 00:00:29,235 --> 00:00:31,710 read the documentation for a more advanced stuff, 11 00:00:31,710 --> 00:00:33,945 but in let's say, 80 percent of the cases 12 00:00:33,945 --> 00:00:36,675 that I will tell you now is sufficient. 13 00:00:36,675 --> 00:00:41,010 Let's actually start using GitHub. 14 00:00:41,010 --> 00:00:45,315 It makes things a bit more easy. 15 00:00:45,315 --> 00:00:53,670 There's also competition to GitHub. This is GitLab. 16 00:00:53,670 --> 00:00:55,880 GitLab is particular interesting because 17 00:00:55,880 --> 00:00:58,880 the whole system behind GitLab is open-source. 18 00:00:58,880 --> 00:01:00,350 This is a hosted version, 19 00:01:00,350 --> 00:01:03,830 but you can have the whole system on-prem, 20 00:01:03,830 --> 00:01:07,495 and also purchase support from GitLab. 21 00:01:07,495 --> 00:01:09,260 Those guys are partially in 22 00:01:09,260 --> 00:01:11,015 Berlin, so they are pretty cool. 23 00:01:11,015 --> 00:01:14,630 Anyway, let's start with GitHub here. 24 00:01:14,630 --> 00:01:18,355 What I will do now is create a repository. 25 00:01:18,355 --> 00:01:26,265 A repository is the location where your stuff goes into. 26 00:01:26,265 --> 00:01:29,650 Let's call it, I don't know, 27 00:01:29,870 --> 00:01:33,890 demo, and we can choose 28 00:01:33,890 --> 00:01:35,150 whether we want to create 29 00:01:35,150 --> 00:01:37,385 a public or a private repository. 30 00:01:37,385 --> 00:01:39,215 That repository is remote, 31 00:01:39,215 --> 00:01:41,075 that's hosted at GitHub, 32 00:01:41,075 --> 00:01:44,580 and let's initialize with a README. 33 00:01:45,740 --> 00:01:48,840 Let's skip gitignore for now, 34 00:01:48,840 --> 00:01:50,280 I will show you that later. 35 00:01:50,280 --> 00:01:53,230 We create now repository. 36 00:01:53,300 --> 00:01:55,745 Once this is created, 37 00:01:55,745 --> 00:02:01,070 it's very easy to have a copy of this repository locally. 38 00:02:01,070 --> 00:02:03,785 There are two options: one is 39 00:02:03,785 --> 00:02:07,085 cloning it via HTTPS or via SSH. 40 00:02:07,085 --> 00:02:09,170 I'm always using SSH, 41 00:02:09,170 --> 00:02:12,185 it just to make things a bit more easy. 42 00:02:12,185 --> 00:02:16,175 The only thing you need to do is you have to add 43 00:02:16,175 --> 00:02:20,385 your public identity to GitHub. 44 00:02:20,385 --> 00:02:22,635 I can show you that later. 45 00:02:22,635 --> 00:02:26,445 Now, the only thing we need to do 46 00:02:26,445 --> 00:02:32,700 is we go to empty folder, 47 00:02:32,700 --> 00:02:43,155 and then we say git clone, and this link. 48 00:02:43,155 --> 00:02:46,210 What now happens is the contents 49 00:02:46,210 --> 00:02:49,210 of this is copied to my machine. 50 00:02:49,210 --> 00:02:57,570 Here, I have to specify my password for my SSH identity, 51 00:02:57,570 --> 00:02:59,650 so that's something I need to explain you later. 52 00:02:59,650 --> 00:03:02,140 If you know, go to demo. 53 00:03:02,140 --> 00:03:05,780 You will see here the README file, 54 00:03:08,630 --> 00:03:14,715 and you see here there is content of the README file. 55 00:03:14,715 --> 00:03:17,620 Now, let's add a file. 56 00:03:26,180 --> 00:03:31,665 You see here there's only the README, and the.git folder. 57 00:03:31,665 --> 00:03:34,570 Please never ever touch it. 58 00:03:35,690 --> 00:03:38,385 Let's create another file. 59 00:03:38,385 --> 00:03:41,610 Let's say, vi test.txt, 60 00:03:41,610 --> 00:03:46,590 and hello, this is a test. 61 00:03:46,590 --> 00:03:50,670 Now, we add this to the repo. 62 00:03:50,670 --> 00:03:53,835 First of all, we say git add test.txt. 63 00:03:53,835 --> 00:03:56,820 Now, if we say now git status, 64 00:03:56,820 --> 00:03:59,220 then we see that this file 65 00:03:59,220 --> 00:04:01,770 is now in the so-called staging area. 66 00:04:01,770 --> 00:04:06,290 That's something in-between your local folder 67 00:04:06,290 --> 00:04:08,610 and your local repository. 68 00:04:08,610 --> 00:04:11,240 You have a local folder with the contents, 69 00:04:11,240 --> 00:04:12,965 you have a local repository, 70 00:04:12,965 --> 00:04:15,455 and you have a remote repository. 71 00:04:15,455 --> 00:04:18,770 Personally, you work with your local repository, 72 00:04:18,770 --> 00:04:21,275 and all the other guys working together with you 73 00:04:21,275 --> 00:04:24,470 are working also with their local repositories, 74 00:04:24,470 --> 00:04:28,960 and do sync all your contents with the remote repository. 75 00:04:28,960 --> 00:04:33,030 Now, we want to commit or let's do something else. 76 00:04:33,030 --> 00:04:38,710 Let's say, we create a file test2, 77 00:04:38,930 --> 00:04:45,375 and we say git add test2.txt. 78 00:04:45,375 --> 00:04:49,500 Now interestingly, if we now say git status, 79 00:04:49,500 --> 00:04:52,480 those are both in the staging area. 80 00:04:52,480 --> 00:04:54,400 Now, if we say git commit, 81 00:04:54,400 --> 00:04:58,450 and we say message initial commit, 82 00:04:58,450 --> 00:05:04,720 and that is now in our local repository on this machine. 83 00:05:04,720 --> 00:05:07,180 The idea is why you have the staging area, 84 00:05:07,180 --> 00:05:09,745 you can control which files 85 00:05:09,745 --> 00:05:12,680 go into a commit because let's say, 86 00:05:12,680 --> 00:05:16,685 the atomic entity here in git is a commit, 87 00:05:16,685 --> 00:05:19,505 so everything is around beat on the commit. 88 00:05:19,505 --> 00:05:21,720 You can yet definitely control 89 00:05:21,720 --> 00:05:24,420 which files are going into a single commit. 90 00:05:24,420 --> 00:05:28,060 Now, what you want to do is you want to push 91 00:05:28,060 --> 00:05:29,080 the contents of 92 00:05:29,080 --> 00:05:32,260 your local repository to remote repository. 93 00:05:32,260 --> 00:05:35,545 Because if you now go to this here, 94 00:05:35,545 --> 00:05:38,970 to this GitHub project, 95 00:05:38,970 --> 00:05:43,215 you see that there is no additional file. 96 00:05:43,215 --> 00:05:46,330 We say now, git push. 97 00:05:46,640 --> 00:05:49,005 What now happens is, 98 00:05:49,005 --> 00:05:50,650 I again have to provide a password. 99 00:05:50,650 --> 00:05:54,915 I don't have the key agent that running. 100 00:05:54,915 --> 00:05:57,415 Now, you see here we have committed 101 00:05:57,415 --> 00:05:58,840 this local change in 102 00:05:58,840 --> 00:06:02,225 the local repository to remote repository. 103 00:06:02,225 --> 00:06:06,330 Now, you can see that you have these two files here. 104 00:06:06,330 --> 00:06:07,780 If you click on that "File", 105 00:06:07,780 --> 00:06:10,320 you'll see first of all the content, 106 00:06:10,320 --> 00:06:12,770 and also you'll see here which commit 107 00:06:12,770 --> 00:06:16,200 was responsible for adding this file. 108 00:06:16,490 --> 00:06:19,640 Another interesting thing is 109 00:06:19,640 --> 00:06:22,715 if you are starting from scratch, 110 00:06:22,715 --> 00:06:26,165 you can also do the following: Now, 111 00:06:26,165 --> 00:06:30,370 let's delete this project, 112 00:06:30,370 --> 00:06:33,165 and this is a bit hard. 113 00:06:33,165 --> 00:06:36,350 Just to make sure you don't do that accidentally, 114 00:06:36,350 --> 00:06:37,820 so delete this repository, 115 00:06:37,820 --> 00:06:40,925 and you have to say demo here, 116 00:06:40,925 --> 00:06:45,085 although I think you have to type the whole thing here. 117 00:06:45,085 --> 00:06:48,250 Now, this project is deleted. 118 00:06:58,550 --> 00:07:01,590 Let's do something else. 119 00:07:01,590 --> 00:07:04,095 Let's create a new repository, 120 00:07:04,095 --> 00:07:07,435 but now let's init a repository on my machine. 121 00:07:07,435 --> 00:07:10,250 Let's call it demo again. 122 00:07:10,500 --> 00:07:13,255 We don't initialize it with a README. 123 00:07:13,255 --> 00:07:16,180 We say create repository. 124 00:07:16,180 --> 00:07:18,730 If you're lucky, GitHub will show 125 00:07:18,730 --> 00:07:20,995 us how to do it. Yeah, here. 126 00:07:20,995 --> 00:07:24,300 Let's actually do it ourselves. 127 00:07:24,300 --> 00:07:28,720 Let's get rid of the demo folder, 128 00:07:30,170 --> 00:07:33,460 and let's create it again. 129 00:07:35,420 --> 00:07:38,340 Now, do what they tell us. 130 00:07:38,340 --> 00:07:40,035 We create a README, 131 00:07:40,035 --> 00:07:43,420 and let me say, git init. 132 00:07:43,520 --> 00:07:46,950 Now, we have it initialized because now 133 00:07:46,950 --> 00:07:50,160 we have the.git folder which you never ever should touch. 134 00:07:50,160 --> 00:07:54,270 We say git add README, 135 00:07:54,270 --> 00:07:56,520 but we can also say git add., 136 00:07:56,520 --> 00:08:01,595 so it's adding everything which was in our folder. 137 00:08:01,595 --> 00:08:03,590 It's only the README.md, 138 00:08:03,590 --> 00:08:05,030 and then we say, 139 00:08:05,030 --> 00:08:10,780 git commit as usual, test or whatever. 140 00:08:10,780 --> 00:08:14,235 Now, we can't say git push now. 141 00:08:14,235 --> 00:08:15,885 If we say git push, 142 00:08:15,885 --> 00:08:17,975 it doesn't know where to push it 143 00:08:17,975 --> 00:08:19,850 because actually we haven't 144 00:08:19,850 --> 00:08:21,620 told this local folder that it should 145 00:08:21,620 --> 00:08:23,720 connect to remote repository. 146 00:08:23,720 --> 00:08:30,194 That we do with git remote add origin, 147 00:08:30,194 --> 00:08:34,320 and that's the URL of our project. 148 00:08:34,320 --> 00:08:38,870 Then we can say git push u origin master, 149 00:08:38,870 --> 00:08:41,240 and that's basically it. 150 00:08:41,240 --> 00:08:49,760 We have to re-enter the password for my RSA key, 151 00:08:49,760 --> 00:08:51,410 and if you're lucky, 152 00:08:51,410 --> 00:08:52,880 and everything worked fine, 153 00:08:52,880 --> 00:08:54,710 we can now go to the project, 154 00:08:54,710 --> 00:08:56,610 and we should see the README file, 155 00:08:56,610 --> 00:08:58,125 which is the case. 156 00:08:58,125 --> 00:09:00,390 That's it for now. That's the first part. 157 00:09:00,390 --> 00:09:04,100 In the next video, I will show you how to do branches, 158 00:09:04,100 --> 00:09:07,315 and actually also how to create a pull request. 159 00:09:07,315 --> 00:09:10,390 Thanks for watching, and see you later.