1 00:00:06,780 --> 00:00:08,670 - Let's talk about Git. 2 00:00:08,670 --> 00:00:11,493 Git is a distributed version control system. 3 00:00:12,420 --> 00:00:14,970 It allows developers to work in products together, 4 00:00:14,970 --> 00:00:18,240 where each file revision is stored in the system. 5 00:00:18,240 --> 00:00:20,580 Old versions of files are always available, 6 00:00:20,580 --> 00:00:22,230 and the log is maintained 7 00:00:22,230 --> 00:00:25,350 of who made what change to which file. 8 00:00:25,350 --> 00:00:26,490 Git is distributed 9 00:00:26,490 --> 00:00:28,980 because it allows developers to work offline 10 00:00:28,980 --> 00:00:31,980 after cloning a remote repository locally, 11 00:00:31,980 --> 00:00:34,740 and that makes it a very popular platform. 12 00:00:34,740 --> 00:00:36,480 Git works with a repository, 13 00:00:36,480 --> 00:00:39,540 which can contain different development branches. 14 00:00:39,540 --> 00:00:41,970 Developers and users can easily upload as well 15 00:00:41,970 --> 00:00:45,330 as download new files to and from the Git repository, 16 00:00:45,330 --> 00:00:48,093 and in order to do so, a Git client is needed. 17 00:00:49,170 --> 00:00:52,320 Git clients are available for all operating system. 18 00:00:52,320 --> 00:00:55,800 No matter if you work on Windows, Mac, or Linux, 19 00:00:55,800 --> 00:00:57,153 you'll find a Git client. 20 00:00:58,710 --> 00:01:00,900 At the other end there's the Git platform. 21 00:01:00,900 --> 00:01:03,330 GitHub is a very common platform, 22 00:01:03,330 --> 00:01:05,340 GitLab is a common alternative, 23 00:01:05,340 --> 00:01:08,460 and private Git servers can also be hosted. 24 00:01:08,460 --> 00:01:10,650 In this lesson, I'll be focusing on GitHub, 25 00:01:10,650 --> 00:01:13,020 because it's the most common platform 26 00:01:13,020 --> 00:01:16,053 and all Linux development is mainly happening on GitHub. 27 00:01:17,100 --> 00:01:18,840 To work with Git successfully, 28 00:01:18,840 --> 00:01:22,050 It helps if you understand the Git workflow. 29 00:01:22,050 --> 00:01:24,210 After cloning, the developer makes changes 30 00:01:24,210 --> 00:01:25,383 to the working tree. 31 00:01:26,220 --> 00:01:29,220 All changes are made to the local repository, 32 00:01:29,220 --> 00:01:33,450 and developers can push changes to the remote repository. 33 00:01:33,450 --> 00:01:36,720 And if the local repository is network accessible, 34 00:01:36,720 --> 00:01:39,840 the owner of the repository can even pull changes from it, 35 00:01:39,840 --> 00:01:41,460 but that's pretty uncommon. 36 00:01:41,460 --> 00:01:44,643 Normally the push is developer initiated. 37 00:01:46,170 --> 00:01:49,290 Now in Git, there are these different trees. 38 00:01:49,290 --> 00:01:53,160 The Git repository has three trees in total 39 00:01:53,160 --> 00:01:54,840 and these trees are stored as files 40 00:01:54,840 --> 00:01:57,843 in the .git directory on the developer workstation. 41 00:01:59,190 --> 00:02:02,190 The working directory holds the actual files, 42 00:02:02,190 --> 00:02:05,010 the index acts as a staging area 43 00:02:05,010 --> 00:02:08,013 and the HEAD points to the last commit that was made. 44 00:02:09,120 --> 00:02:10,170 We're working with Git, 45 00:02:10,170 --> 00:02:14,190 the git add command is used to add files to the index. 46 00:02:14,190 --> 00:02:15,510 I'll show you all about that, 47 00:02:15,510 --> 00:02:17,700 but first I want to give you the overview. 48 00:02:17,700 --> 00:02:20,130 So git add is the first step. 49 00:02:20,130 --> 00:02:22,530 Next, you are going to commit the files 50 00:02:22,530 --> 00:02:23,610 that you have just added 51 00:02:23,610 --> 00:02:27,690 to the HEAD using git commit followed by a commit message. 52 00:02:27,690 --> 00:02:30,840 This commit message is also published on the Git website, 53 00:02:30,840 --> 00:02:33,480 so it's pretty important to make a clear message 54 00:02:33,480 --> 00:02:36,183 so the users can see what exactly has changed. 55 00:02:38,370 --> 00:02:39,750 Now, in order to connect 56 00:02:39,750 --> 00:02:42,240 to a remote repository from the client, 57 00:02:42,240 --> 00:02:44,400 you need git add origin 58 00:02:44,400 --> 00:02:46,890 and that will make the connection for you. 59 00:02:46,890 --> 00:02:48,480 And on the Git client, 60 00:02:48,480 --> 00:02:52,109 you identify this Git remote repository next 61 00:02:52,109 --> 00:02:54,930 by using git remote add origin, 62 00:02:54,930 --> 00:02:56,880 where origin is the identifier 63 00:02:56,880 --> 00:02:59,490 for the Git repository, it can be anything. 64 00:02:59,490 --> 00:03:02,190 Instead of origin, you will also find main 65 00:03:02,190 --> 00:03:03,603 and master for instance. 66 00:03:04,710 --> 00:03:08,190 So to complete the sequence, you use git push origin main, 67 00:03:08,190 --> 00:03:10,140 and there you replace the name main 68 00:03:10,140 --> 00:03:13,383 with your actual branch that you want to push changes to. 69 00:03:15,570 --> 00:03:18,660 Alright, let's try to understand the Git procedure. 70 00:03:18,660 --> 00:03:20,830 So it all starts on the Git server 71 00:03:24,480 --> 00:03:25,841 and from the get server, 72 00:03:25,841 --> 00:03:29,283 you are going to use git clone command. 73 00:03:30,270 --> 00:03:32,040 And this get clone command 74 00:03:32,040 --> 00:03:35,940 or git pull command comes down to the same. 75 00:03:35,940 --> 00:03:38,070 That makes that you have your files 76 00:03:38,070 --> 00:03:40,683 on what we will call the Git client. 77 00:03:43,890 --> 00:03:45,000 Now, from the Git client, 78 00:03:45,000 --> 00:03:47,550 you are going to work with your files. 79 00:03:47,550 --> 00:03:49,500 So we call it the working directory 80 00:03:49,500 --> 00:03:52,653 and that is where you are going to add your files. 81 00:03:53,820 --> 00:03:57,453 So, in the working directory, you apply your changes, 82 00:03:58,620 --> 00:04:02,823 and these changes need to be added using git add. 83 00:04:06,630 --> 00:04:09,180 Now, while working with Git, your files 84 00:04:09,180 --> 00:04:12,360 and these files can be in different states. 85 00:04:12,360 --> 00:04:13,860 You can use git status 86 00:04:13,860 --> 00:04:16,590 to figure out what the actual state is. 87 00:04:16,590 --> 00:04:18,753 So the three states are modified. 88 00:04:19,620 --> 00:04:21,630 So modified is what you get 89 00:04:21,630 --> 00:04:23,670 if the file in the working tree is different 90 00:04:23,670 --> 00:04:26,010 from the file in the repository. 91 00:04:26,010 --> 00:04:28,950 Staged is where the modified file was added 92 00:04:28,950 --> 00:04:31,620 to a list of changed files in the index. 93 00:04:31,620 --> 00:04:34,440 And committed is where the modified file has been committed 94 00:04:34,440 --> 00:04:37,290 to the HEAD and is ready to be pushed. 95 00:04:37,290 --> 00:04:39,630 After committing a file to the local repository, 96 00:04:39,630 --> 00:04:42,123 it can be pushed to the remote repository. 97 00:04:42,960 --> 00:04:44,250 Now that we know a little bit 98 00:04:44,250 --> 00:04:47,310 in general about the working of Git, 99 00:04:47,310 --> 00:04:50,253 let's further explore and let's talk about authentication.