WEBVTT 00:00:00.000 --> 00:00:02.700 align:middle line:90% 00:00:02.700 --> 00:00:04.690 align:middle line:84% BERNIE LONGBOY: Good afternoon, everyone. 00:00:04.690 --> 00:00:07.780 align:middle line:90% Welcome from Cambridge, Massachusetts. 00:00:07.780 --> 00:00:13.350 align:middle line:84% Welcome to today's seminar on collaboration and version control 00:00:13.350 --> 00:00:15.090 align:middle line:90% with Git. 00:00:15.090 --> 00:00:19.440 align:middle line:84% Today we have Tarun Prasad, a junior and computer science major 00:00:19.440 --> 00:00:22.350 align:middle line:90% and one of our CS50 teaching fellows. 00:00:22.350 --> 00:00:26.990 align:middle line:84% I'm Bernie Longboy, one of the staff members and your moderator for today. 00:00:26.990 --> 00:00:29.715 align:middle line:90% Welcome, and thank you, to Tarun. 00:00:29.715 --> 00:00:32.820 align:middle line:84% TARUN PRASAD: Thanks so much, Bernie, and thank you all for joining. 00:00:32.820 --> 00:00:36.000 align:middle line:90% Very good afternoon to all of you. 00:00:36.000 --> 00:00:39.420 align:middle line:84% So like Bernie said, the topic that we'll be talking about today 00:00:39.420 --> 00:00:43.500 align:middle line:84% is using this command-line tool called Git 00:00:43.500 --> 00:00:48.330 align:middle line:90% for version control and collaboration. 00:00:48.330 --> 00:00:52.140 align:middle line:84% So before we start talking about Git is or what we can do with it, 00:00:52.140 --> 00:00:55.850 align:middle line:90% consider the following two scenarios. 00:00:55.850 --> 00:00:59.320 align:middle line:84% The first scenario is that you're working on a CS50 problem set, 00:00:59.320 --> 00:01:00.687 align:middle line:90% say Finance. 00:01:00.687 --> 00:01:03.520 align:middle line:84% And you're able to get some portions of the P set working perfectly, 00:01:03.520 --> 00:01:06.640 align:middle line:84% so things like register, and quote, and buy. 00:01:06.640 --> 00:01:09.370 align:middle line:84% But you're confused as to how to complete index and display 00:01:09.370 --> 00:01:12.680 align:middle line:90% a table of stocks that the user owns. 00:01:12.680 --> 00:01:14.960 align:middle line:84% And while attempting to make more progress, 00:01:14.960 --> 00:01:18.180 align:middle line:84% you accidentally mess up the working code that you already had. 00:01:18.180 --> 00:01:21.350 align:middle line:84% And so now all that you see are internal server errors everywhere, 00:01:21.350 --> 00:01:23.543 align:middle line:90% no matter what you try to do. 00:01:23.543 --> 00:01:25.460 align:middle line:84% So in hindsight, what are some things that you 00:01:25.460 --> 00:01:27.050 align:middle line:90% could have done to prevent this? 00:01:27.050 --> 00:01:30.500 align:middle line:84% And feel free to use the chat to send in your answers, 00:01:30.500 --> 00:01:34.010 align:middle line:90% and we can talk about some of them. 00:01:34.010 --> 00:01:44.030 align:middle line:90% 00:01:44.030 --> 00:01:47.280 align:middle line:84% What are some things that you could have done to prevent this from happening? 00:01:47.280 --> 00:01:50.460 align:middle line:90% How could you have? 00:01:50.460 --> 00:01:53.760 align:middle line:84% You could have used some sort of version control, the version control. 00:01:53.760 --> 00:01:57.240 align:middle line:90% Yes, use Git. 00:01:57.240 --> 00:01:59.040 align:middle line:90% You could have made some backups. 00:01:59.040 --> 00:02:01.330 align:middle line:84% Some of you are suggesting using some sort of backup, 00:02:01.330 --> 00:02:02.760 align:middle line:90% so that could be a good idea. 00:02:02.760 --> 00:02:08.190 align:middle line:84% You could have copied over your entire codebase, zip it into a ZIP file, 00:02:08.190 --> 00:02:09.320 align:middle line:90% store it on your desktop. 00:02:09.320 --> 00:02:11.820 align:middle line:84% And full disclosure-- I've definitely done this in the past. 00:02:11.820 --> 00:02:14.390 align:middle line:90% 00:02:14.390 --> 00:02:18.350 align:middle line:84% You could absolutely do that, and maybe you would do that once every day. 00:02:18.350 --> 00:02:23.732 align:middle line:84% At the end of every day, you just create a ZIP backup of your entire code space. 00:02:23.732 --> 00:02:25.690 align:middle line:84% The main problem with doing something like that 00:02:25.690 --> 00:02:29.770 align:middle line:84% is, especially if your codebase is really large-- 00:02:29.770 --> 00:02:34.120 align:middle line:84% imagine you have a really large number of images and videos 00:02:34.120 --> 00:02:36.190 align:middle line:90% within your codebase-- 00:02:36.190 --> 00:02:38.870 align:middle line:84% you would have to make multiple copies of that. 00:02:38.870 --> 00:02:44.140 align:middle line:84% And so this can very quickly become very large and take up a lot of space 00:02:44.140 --> 00:02:46.640 align:middle line:90% unnecessarily. 00:02:46.640 --> 00:02:50.330 align:middle line:84% Now, one of you is suggesting that you can take a note of the changes 00:02:50.330 --> 00:02:51.380 align:middle line:90% that we made. 00:02:51.380 --> 00:02:53.220 align:middle line:84% So that could be another really good idea. 00:02:53.220 --> 00:02:54.650 align:middle line:90% Maybe we just open a Google Doc. 00:02:54.650 --> 00:03:01.470 align:middle line:84% And maybe every single day, we write down, OK, I added lines 23 to 30 00:03:01.470 --> 00:03:04.580 align:middle line:90% as these specific lines of code. 00:03:04.580 --> 00:03:07.580 align:middle line:84% I deleted line 15, and then I modified line 14 00:03:07.580 --> 00:03:09.838 align:middle line:90% by adding a semicolon at the end. 00:03:09.838 --> 00:03:11.630 align:middle line:84% And that could be another really useful way 00:03:11.630 --> 00:03:15.710 align:middle line:84% of managing this sort of a situation, where we don't actually 00:03:15.710 --> 00:03:16.670 align:middle line:90% use up as much space. 00:03:16.670 --> 00:03:20.810 align:middle line:90% 00:03:20.810 --> 00:03:24.290 align:middle line:84% So thank you for the ideas, and let's go on to scenario two. 00:03:24.290 --> 00:03:27.100 align:middle line:90% 00:03:27.100 --> 00:03:30.880 align:middle line:84% So let's say you decide to team up with a friend for your CS50 final project, 00:03:30.880 --> 00:03:33.153 align:middle line:90% and you want to build a web app. 00:03:33.153 --> 00:03:35.570 align:middle line:84% The two of you are trying to decide how to split up tasks. 00:03:35.570 --> 00:03:38.970 align:middle line:84% You really want to design the home page, using HTML and CSS, 00:03:38.970 --> 00:03:42.922 align:middle line:84% including the fonts, the styles, the colors, the text, et cetera. 00:03:42.922 --> 00:03:44.630 align:middle line:84% But your friend really wants to implement 00:03:44.630 --> 00:03:47.390 align:middle line:84% the sign-up and log-in workflow, so the HTML form, 00:03:47.390 --> 00:03:52.720 align:middle line:84% as well as some of the JavaScript, as well as the Flash backend. 00:03:52.720 --> 00:03:56.218 align:middle line:84% So given that you both want to edit the same files, but in different ways, 00:03:56.218 --> 00:03:57.760 align:middle line:90% what are some ways to deal with this? 00:03:57.760 --> 00:04:01.937 align:middle line:90% 00:04:01.937 --> 00:04:05.270 align:middle line:84% And again, feel free to send messages in the chat, and we can talk through them. 00:04:05.270 --> 00:04:12.050 align:middle line:90% 00:04:12.050 --> 00:04:14.900 align:middle line:84% You can use an IDE that has real-time collaboration. 00:04:14.900 --> 00:04:16.189 align:middle line:90% Yeah, that absolutely works. 00:04:16.189 --> 00:04:20.700 align:middle line:90% 00:04:20.700 --> 00:04:22.364 align:middle line:90% Communication before doing any changes. 00:04:22.364 --> 00:04:24.435 align:middle line:90% 00:04:24.435 --> 00:04:27.560 align:middle line:84% Some of you are suggesting Git branches, which is a really good idea, which 00:04:27.560 --> 00:04:28.670 align:middle line:90% we'll come to later today. 00:04:28.670 --> 00:04:39.560 align:middle line:90% 00:04:39.560 --> 00:04:41.090 align:middle line:90% Any other thoughts? 00:04:41.090 --> 00:04:41.750 align:middle line:90% Git branches? 00:04:41.750 --> 00:04:48.800 align:middle line:90% 00:04:48.800 --> 00:04:49.520 align:middle line:90% Using Replit. 00:04:49.520 --> 00:04:51.950 align:middle line:84% Yeah, using some sort of a collaborative code writer. 00:04:51.950 --> 00:04:55.220 align:middle line:84% Maybe even in the worst case, Google Docs, maybe 00:04:55.220 --> 00:04:58.100 align:middle line:84% copying over your entire file into Google Docs, 00:04:58.100 --> 00:05:00.650 align:middle line:84% and manually spacing everything and typing everything 00:05:00.650 --> 00:05:02.443 align:middle line:90% until everything looks OK. 00:05:02.443 --> 00:05:03.110 align:middle line:90% That might work. 00:05:03.110 --> 00:05:09.880 align:middle line:84% But I mean, some other ideas might also be using something like-- 00:05:09.880 --> 00:05:12.620 align:middle line:84% or just taking turns sitting at the same device. 00:05:12.620 --> 00:05:16.270 align:middle line:84% And maybe one person types code first, and then the other person takes over. 00:05:16.270 --> 00:05:19.750 align:middle line:84% And again, you can see that many of these have disadvantages. 00:05:19.750 --> 00:05:24.160 align:middle line:84% Either these ideas are somewhat slow, or maybe two people 00:05:24.160 --> 00:05:26.750 align:middle line:84% work on the two different things simultaneously. 00:05:26.750 --> 00:05:31.390 align:middle line:84% And then one person sends over their changes to the other person via email, 00:05:31.390 --> 00:05:34.870 align:middle line:84% and the other person then merges them in by going through it line by line 00:05:34.870 --> 00:05:38.210 align:middle line:90% and seeing what changed. 00:05:38.210 --> 00:05:40.580 align:middle line:84% Yeah, so thanks again for the great ideas. 00:05:40.580 --> 00:05:43.850 align:middle line:90% 00:05:43.850 --> 00:05:46.160 align:middle line:84% A lot of these involve a lot of manual work 00:05:46.160 --> 00:05:49.520 align:middle line:90% and can often be slow or time-consuming. 00:05:49.520 --> 00:05:52.430 align:middle line:84% And that's where this command-line tool called Git comes in. 00:05:52.430 --> 00:05:55.560 align:middle line:90% 00:05:55.560 --> 00:05:58.990 align:middle line:84% Git is essentially a command-line version control system, 00:05:58.990 --> 00:06:01.500 align:middle line:84% which means it automates a lot of the ideas 00:06:01.500 --> 00:06:04.020 align:middle line:84% that we just spoke about, storing differences 00:06:04.020 --> 00:06:08.160 align:middle line:84% between different versions of your codebase, 00:06:08.160 --> 00:06:13.020 align:middle line:84% or allowing collaboration, allowing different people to work 00:06:13.020 --> 00:06:16.200 align:middle line:84% on the same files in different locations, 00:06:16.200 --> 00:06:20.160 align:middle line:84% and enabling you to merge them together in a very easy and straightforward way. 00:06:20.160 --> 00:06:23.690 align:middle line:90% 00:06:23.690 --> 00:06:28.760 align:middle line:84% So in Git, each project is stored as a repository. 00:06:28.760 --> 00:06:34.160 align:middle line:84% And each saved version of the repository is called a commit. 00:06:34.160 --> 00:06:37.010 align:middle line:84% A local repository on your device can be associated 00:06:37.010 --> 00:06:40.580 align:middle line:84% with other repositories hosted elsewhere, like on GitHub and GitLab. 00:06:40.580 --> 00:06:46.650 align:middle line:84% And these repositories hosted on other servers are called remotes. 00:06:46.650 --> 00:06:50.740 align:middle line:84% So your repository consists of both a history of the commits that you made, 00:06:50.740 --> 00:06:54.180 align:middle line:84% so all of the previous versions of your codebase, 00:06:54.180 --> 00:06:55.440 align:middle line:90% as well as the latest version. 00:06:55.440 --> 00:06:58.550 align:middle line:90% 00:06:58.550 --> 00:07:01.460 align:middle line:84% Each commit stores the changes made since the previous commit, 00:07:01.460 --> 00:07:04.215 align:middle line:90% and is identified through a commit hash. 00:07:04.215 --> 00:07:06.590 align:middle line:84% And so I'm sure most of you have heard of hash functions, 00:07:06.590 --> 00:07:09.290 align:middle line:84% and so that's essentially what's used over here. 00:07:09.290 --> 00:07:13.250 align:middle line:84% Each commit stores what changes you've made since the previous commit. 00:07:13.250 --> 00:07:15.530 align:middle line:84% And then that information is somehow hashed 00:07:15.530 --> 00:07:19.448 align:middle line:90% to give you a hexadecimal number. 00:07:19.448 --> 00:07:21.240 align:middle line:84% And any time you want to refer to a commit, 00:07:21.240 --> 00:07:25.728 align:middle line:84% you can identify it, using this commit hash. 00:07:25.728 --> 00:07:28.770 align:middle line:84% The normal directory structure on your local system, along with the files 00:07:28.770 --> 00:07:34.760 align:middle line:84% it contains, as opposed to previous versions, is called a working copy. 00:07:34.760 --> 00:07:37.580 align:middle line:84% The set of tracked changes that will be saved in the next commit 00:07:37.580 --> 00:07:38.750 align:middle line:90% is called the staging area. 00:07:38.750 --> 00:07:41.700 align:middle line:90% 00:07:41.700 --> 00:07:45.470 align:middle line:84% And so this is a diagram from another class called CS61. 00:07:45.470 --> 00:07:49.820 align:middle line:84% And this gives you an example of what the repository contains. 00:07:49.820 --> 00:07:53.060 align:middle line:84% It contains what's called the version repository, which 00:07:53.060 --> 00:07:55.470 align:middle line:84% consists of all of the commits that you made previously, 00:07:55.470 --> 00:07:57.740 align:middle line:84% so all of the previous versions of your codebase, 00:07:57.740 --> 00:08:00.160 align:middle line:84% along with the version that you are working on right now, 00:08:00.160 --> 00:08:01.160 align:middle line:90% called the working copy. 00:08:01.160 --> 00:08:04.150 align:middle line:90% 00:08:04.150 --> 00:08:07.720 align:middle line:84% So I know these were a lot of terms just forced onto you, 00:08:07.720 --> 00:08:12.940 align:middle line:84% but hopefully, this will be useful in understanding how Git works. 00:08:12.940 --> 00:08:16.525 align:middle line:84% And we go through the details of how exactly to use Git next. 00:08:16.525 --> 00:08:21.500 align:middle line:90% 00:08:21.500 --> 00:08:23.340 align:middle line:90% A quick note on the installation. 00:08:23.340 --> 00:08:27.228 align:middle line:84% If you're using Codespaces, like you do for your CS50 problem sets, 00:08:27.228 --> 00:08:29.270 align:middle line:84% then you don't actually have to install anything. 00:08:29.270 --> 00:08:31.310 align:middle line:90% Git should come pre-installed. 00:08:31.310 --> 00:08:35.720 align:middle line:84% If you do want to develop locally, then you can install it, 00:08:35.720 --> 00:08:37.340 align:middle line:90% using this link on Windows. 00:08:37.340 --> 00:08:40.110 align:middle line:84% Or in MacOS, it should probably be installed, but if it's not, 00:08:40.110 --> 00:08:44.890 align:middle line:84% then you can run git --version and it should prompt the installation. 00:08:44.890 --> 00:08:49.520 align:middle line:84% These links are in the slides, so you can definitely 00:08:49.520 --> 00:08:51.400 align:middle line:84% download the slides from the CS50 website, 00:08:51.400 --> 00:08:53.650 align:middle line:90% and you can download Git if you want to. 00:08:53.650 --> 00:08:57.800 align:middle line:90% 00:08:57.800 --> 00:08:59.795 align:middle line:90% Now let's go on to the Git commands. 00:08:59.795 --> 00:09:02.598 align:middle line:90% 00:09:02.598 --> 00:09:04.640 align:middle line:84% The first set of commands that are useful to know 00:09:04.640 --> 00:09:06.680 align:middle line:90% are the getting-started commands. 00:09:06.680 --> 00:09:10.050 align:middle line:84% So how do you get started with a Git repository? 00:09:10.050 --> 00:09:11.430 align:middle line:90% There are a couple of ways. 00:09:11.430 --> 00:09:13.770 align:middle line:84% And which one you use depends on whether you're 00:09:13.770 --> 00:09:16.890 align:middle line:84% working with an existing repository that someone's already published, 00:09:16.890 --> 00:09:21.220 align:middle line:84% or if you're creating a new code space completely from scratch. 00:09:21.220 --> 00:09:24.850 align:middle line:84% For your final project, you probably will use the latter 00:09:24.850 --> 00:09:27.910 align:middle line:84% because you will be starting a new project from scratch. 00:09:27.910 --> 00:09:31.100 align:middle line:84% And in such cases, you will use the command, git init, 00:09:31.100 --> 00:09:34.000 align:middle line:84% which means just initialize the folder that you're in right now 00:09:34.000 --> 00:09:36.570 align:middle line:90% as a Git repository. 00:09:36.570 --> 00:09:40.080 align:middle line:84% On the other hand, if you want to download an existing remote 00:09:40.080 --> 00:09:43.890 align:middle line:84% repository-- for example, something that you found on GitHub for whatever 00:09:43.890 --> 00:09:44.670 align:middle line:90% reason-- 00:09:44.670 --> 00:09:47.297 align:middle line:90% then you can use git clone. 00:09:47.297 --> 00:09:49.130 align:middle line:84% I show you a demo of all of this at the end. 00:09:49.130 --> 00:09:52.540 align:middle line:90% But the idea is to just copy the URL. 00:09:52.540 --> 00:09:56.080 align:middle line:84% You git clone URL, and then it'll download the entire repository 00:09:56.080 --> 00:09:58.368 align:middle line:84% and all of the files and directories into the folder 00:09:58.368 --> 00:09:59.410 align:middle line:90% that you're in right now. 00:09:59.410 --> 00:10:04.900 align:middle line:90% 00:10:04.900 --> 00:10:07.500 align:middle line:84% The next set of commands that we're going to go over 00:10:07.500 --> 00:10:09.510 align:middle line:90% are for saving changes. 00:10:09.510 --> 00:10:13.290 align:middle line:84% And these three commands, in my opinion, are by far the most important commands 00:10:13.290 --> 00:10:15.695 align:middle line:90% in today's seminar. 00:10:15.695 --> 00:10:17.820 align:middle line:84% So even if you don't get anything else out of this, 00:10:17.820 --> 00:10:20.730 align:middle line:90% I want you to take back this one slide. 00:10:20.730 --> 00:10:26.830 align:middle line:84% The first one is git add, which specifies which files to track. 00:10:26.830 --> 00:10:30.780 align:middle line:84% And so it tracks these files by adding them to what we call the staging area. 00:10:30.780 --> 00:10:32.970 align:middle line:84% And like we mentioned before, the staging area 00:10:32.970 --> 00:10:38.580 align:middle line:84% is what controls the files and changes that will be saved in the next commit 00:10:38.580 --> 00:10:41.060 align:middle line:90% that you make. 00:10:41.060 --> 00:10:47.500 align:middle line:84% So you can specify, for example, git add hello.py, or git add mario.c. 00:10:47.500 --> 00:10:50.740 align:middle line:84% And you can list out the files, separated by spaces, 00:10:50.740 --> 00:10:55.710 align:middle line:84% and this will track those files by adding them to the staging area. 00:10:55.710 --> 00:10:57.680 align:middle line:84% So the next commit that you make will then 00:10:57.680 --> 00:11:00.750 align:middle line:84% save the changes that have been specified by git add. 00:11:00.750 --> 00:11:05.520 align:middle line:84% So for example, if you change two files, but you only git added one file, 00:11:05.520 --> 00:11:08.220 align:middle line:84% then only that one file will be saved in the next commit. 00:11:08.220 --> 00:11:12.946 align:middle line:84% And so this is useful for specifying exactly what goes into each commit. 00:11:12.946 --> 00:11:14.930 align:middle line:90% The second command for saving changes-- 00:11:14.930 --> 00:11:17.030 align:middle line:84% and this is, arguably, the most important-- 00:11:17.030 --> 00:11:21.050 align:middle line:84% is git commit, which actually creates the commit by saving the track 00:11:21.050 --> 00:11:24.140 align:middle line:90% changes in the form of a commit. 00:11:24.140 --> 00:11:27.500 align:middle line:84% The -m flag specifies a commit message, and so you 00:11:27.500 --> 00:11:31.730 align:middle line:84% can say git commit, -m, and then whatever commit message 00:11:31.730 --> 00:11:33.750 align:middle line:90% that specifies what changes you made. 00:11:33.750 --> 00:11:37.820 align:middle line:84% So for example, this could be something like fix x bug, 00:11:37.820 --> 00:11:43.590 align:middle line:84% or implement y feature, or something like that. 00:11:43.590 --> 00:11:47.780 align:middle line:84% And finally, the last saving-changes command that you need to know 00:11:47.780 --> 00:11:49.820 align:middle line:90% is git push. 00:11:49.820 --> 00:11:53.090 align:middle line:84% So technically, git push is an optional command, 00:11:53.090 --> 00:11:55.100 align:middle line:84% because if you're working entirely locally, 00:11:55.100 --> 00:11:58.885 align:middle line:84% if you don't have a remote associated with your Git repository, 00:11:58.885 --> 00:12:01.010 align:middle line:84% then you can absolutely just do git add and commit, 00:12:01.010 --> 00:12:04.083 align:middle line:84% and everything will be saved in your device. 00:12:04.083 --> 00:12:07.250 align:middle line:84% But if, for whatever reason, let's say, you want to collaborate with someone 00:12:07.250 --> 00:12:12.980 align:middle line:84% and you want somebody else to have access to your git repository, 00:12:12.980 --> 00:12:16.160 align:middle line:84% then you would add a remote, maybe on GitHub or something, 00:12:16.160 --> 00:12:20.720 align:middle line:84% and push your commits, your changes, onto the remote repository. 00:12:20.720 --> 00:12:22.340 align:middle line:90% And you would do that, using git push. 00:12:22.340 --> 00:12:27.960 align:middle line:90% 00:12:27.960 --> 00:12:28.590 align:middle line:90% OK. 00:12:28.590 --> 00:12:31.590 align:middle line:84% And if you have any questions, please send them in the chat, and Bernie 00:12:31.590 --> 00:12:36.650 align:middle line:84% will stop and let me know if there are any questions. 00:12:36.650 --> 00:12:39.170 align:middle line:90% Undoing changes. 00:12:39.170 --> 00:12:41.330 align:middle line:84% The most important command for undoing changes 00:12:41.330 --> 00:12:46.190 align:middle line:84% is git revert, which lets you undo a commit by essentially creating 00:12:46.190 --> 00:12:49.610 align:middle line:84% a new commit that does exactly the opposite of what 00:12:49.610 --> 00:12:52.090 align:middle line:90% the incorrect commit did. 00:12:52.090 --> 00:12:57.580 align:middle line:84% So for example, if you decided to make some design changes to your web app 00:12:57.580 --> 00:13:02.040 align:middle line:84% that you were building, and so you add a bunch of CSS, 00:13:02.040 --> 00:13:03.590 align:middle line:90% maybe you create a new CSS file. 00:13:03.590 --> 00:13:06.580 align:middle line:84% And you add a bunch of CSS that specifies the fonts, and the styles, 00:13:06.580 --> 00:13:09.180 align:middle line:90% and the colors, and stuff like that. 00:13:09.180 --> 00:13:12.860 align:middle line:84% But then you decide to talk about this design with the other people 00:13:12.860 --> 00:13:16.070 align:middle line:84% in your group, and then you realize that, OK, maybe this 00:13:16.070 --> 00:13:19.410 align:middle line:84% isn't the best way forward for your website. 00:13:19.410 --> 00:13:21.485 align:middle line:90% And so you want to undo the changes. 00:13:21.485 --> 00:13:23.360 align:middle line:84% So one way to undo it would be to manually go 00:13:23.360 --> 00:13:26.030 align:middle line:84% back and see what changes you made, and then 00:13:26.030 --> 00:13:29.750 align:middle line:84% manually delete those lines and each of the files that you made the changes in. 00:13:29.750 --> 00:13:33.470 align:middle line:84% But the advantage of using Git is that, because each of these sets of changes 00:13:33.470 --> 00:13:37.040 align:middle line:84% is stored in a commit, you can directly undo all of those changes 00:13:37.040 --> 00:13:42.410 align:middle line:84% by just doing exactly the opposite of what that previous commit did. 00:13:42.410 --> 00:13:46.040 align:middle line:84% Now, how do you specify this commit in the command? 00:13:46.040 --> 00:13:50.870 align:middle line:84% So like I said earlier, each commit has associated with it 00:13:50.870 --> 00:13:55.500 align:middle line:84% a commit hash, which is basically a big hexadecimal number. 00:13:55.500 --> 00:13:58.775 align:middle line:84% And so you can specify this commit by using the commit hash. 00:13:58.775 --> 00:14:01.400 align:middle line:84% In fact, you don't even need to specify the entire commit hash. 00:14:01.400 --> 00:14:03.290 align:middle line:84% Usually, the first, say, five or six digits 00:14:03.290 --> 00:14:09.050 align:middle line:84% will suffice, because that's enough to uniquely identify this commit. 00:14:09.050 --> 00:14:16.550 align:middle line:84% You can also specify the commit by using the HEAD~n syntax. 00:14:16.550 --> 00:14:21.870 align:middle line:84% HEAD represents the latest commit, so HEAD~n would be the nth last commit. 00:14:21.870 --> 00:14:23.870 align:middle line:84% So let's say you wanted to get rid of the commit 00:14:23.870 --> 00:14:25.770 align:middle line:90% that you did five commits ago. 00:14:25.770 --> 00:14:27.200 align:middle line:90% Then you would just say HEAD~file. 00:14:27.200 --> 00:14:30.890 align:middle line:90% 00:14:30.890 --> 00:14:35.170 align:middle line:84% And that's how you undo changes, using Git. 00:14:35.170 --> 00:14:38.440 align:middle line:84% And there are some other general, useful commands-- git 00:14:38.440 --> 00:14:42.740 align:middle line:84% status, which displays the state of the repository and the staging area, git 00:14:42.740 --> 00:14:45.700 align:middle line:84% log, which displays a log of the previous commits in the currently 00:14:45.700 --> 00:14:46.900 align:middle line:90% checked-out branch. 00:14:46.900 --> 00:14:50.260 align:middle line:84% And we'll talk about branches in a bit, but just 00:14:50.260 --> 00:14:54.350 align:middle line:84% think of this as a log of the previous commits that you made. 00:14:54.350 --> 00:14:57.710 align:middle line:84% And finally, git diff displays the changes that you've made. 00:14:57.710 --> 00:15:01.030 align:middle line:84% So for example, if you just do git diff, then it'll show you-- 00:15:01.030 --> 00:15:05.410 align:middle line:84% using the appropriate colors, green or red-- 00:15:05.410 --> 00:15:08.660 align:middle line:84% what changes that you've made since the last commit. 00:15:08.660 --> 00:15:12.940 align:middle line:84% You can also specify the commit hashes of new commits 00:15:12.940 --> 00:15:15.172 align:middle line:84% to ask for the changes between two commits. 00:15:15.172 --> 00:15:17.380 align:middle line:84% So maybe you want to go back and look at what changes 00:15:17.380 --> 00:15:19.630 align:middle line:90% that you made in a specific commit. 00:15:19.630 --> 00:15:24.070 align:middle line:84% You just specify git diff, the first commit hash, the second commit hash, 00:15:24.070 --> 00:15:28.566 align:middle line:84% and it'll show you whatever changes you made. 00:15:28.566 --> 00:15:32.230 align:middle line:84% BERNIE LONGBOY: I'll go ahead and read a couple of questions, Tarun. 00:15:32.230 --> 00:15:36.550 align:middle line:84% So first is, do I need to download anything on Mac to have Git? 00:15:36.550 --> 00:15:37.855 align:middle line:90% Actually, you don't, correct? 00:15:37.855 --> 00:15:38.710 align:middle line:90% Is that correct? 00:15:38.710 --> 00:15:40.418 align:middle line:84% TARUN PRASAD: You don't need to download, 00:15:40.418 --> 00:15:45.490 align:middle line:84% but you can double-check that you have it installed, using git --version. 00:15:45.490 --> 00:15:48.910 align:middle line:84% So just run this in your command line, and it should probably say something 00:15:48.910 --> 00:15:51.345 align:middle line:90% like Git Version 2.25 or something. 00:15:51.345 --> 00:15:52.220 align:middle line:90% BERNIE LONGBOY: Yeah. 00:15:52.220 --> 00:15:52.540 align:middle line:90% TARUN PRASAD: And-- 00:15:52.540 --> 00:15:54.010 align:middle line:84% BERNIE LONGBOY: And I think you answered this one, 00:15:54.010 --> 00:15:56.500 align:middle line:84% but does GitHub count with a visual aid to understand 00:15:56.500 --> 00:15:58.120 align:middle line:90% how many commits we're using? 00:15:58.120 --> 00:16:02.688 align:middle line:84% I'm finding the timeline branches a little confusing. 00:16:02.688 --> 00:16:03.480 align:middle line:90% TARUN PRASAD: Yeah. 00:16:03.480 --> 00:16:10.860 align:middle line:84% I mean, both Git and GitHub do have a list of commits. 00:16:10.860 --> 00:16:14.930 align:middle line:84% You can do this locally without even using GitHub, using git log. 00:16:14.930 --> 00:16:17.430 align:middle line:84% And so that'll give you a list of the commits that you made, 00:16:17.430 --> 00:16:24.480 align:middle line:84% along with a timestamp of when you made the commit, who made the commit, 00:16:24.480 --> 00:16:28.500 align:middle line:84% and other information, what changes were actually made in that commit. 00:16:28.500 --> 00:16:31.650 align:middle line:84% About branches, we will talk about that in about 5 or 10 minutes, 00:16:31.650 --> 00:16:32.340 align:middle line:90% after this demo. 00:16:32.340 --> 00:16:34.590 align:middle line:84% So hopefully, that will clear things up a little more. 00:16:34.590 --> 00:16:41.198 align:middle line:90% 00:16:41.198 --> 00:16:42.190 align:middle line:90% BERNIE LONGBOY: OK. 00:16:42.190 --> 00:16:44.327 align:middle line:90% Those were-- 00:16:44.327 --> 00:16:45.410 align:middle line:90% TARUN PRASAD: OK, awesome. 00:16:45.410 --> 00:16:46.972 align:middle line:84% BERNIE LONGBOY: --good questions they had. 00:16:46.972 --> 00:16:47.764 align:middle line:90% TARUN PRASAD: Yeah. 00:16:47.764 --> 00:16:51.560 align:middle line:84% We will go ahead to a demo right now, so that I can just 00:16:51.560 --> 00:16:53.305 align:middle line:90% show you the basics of what we covered. 00:16:53.305 --> 00:16:55.430 align:middle line:84% And then we'll come back and talk a little bit more 00:16:55.430 --> 00:16:56.638 align:middle line:90% about some of these commands. 00:16:56.638 --> 00:17:11.869 align:middle line:90% 00:17:11.869 --> 00:17:14.270 align:middle line:90% OK. 00:17:14.270 --> 00:17:16.609 align:middle line:84% So what I'm going to do here is, I am going 00:17:16.609 --> 00:17:22.300 align:middle line:84% to create a new folder, which I will call Git Seminar. 00:17:22.300 --> 00:17:25.470 align:middle line:84% This is just CS50 Codespaces, so feel free to pull it up and follow along, 00:17:25.470 --> 00:17:27.400 align:middle line:90% if you like. 00:17:27.400 --> 00:17:30.670 align:middle line:84% You may have to create this folder in the workspace directory, 00:17:30.670 --> 00:17:34.120 align:middle line:84% so you might have to go up one directory to avoid 00:17:34.120 --> 00:17:41.180 align:middle line:84% messing up CS50's own Git commands or the Git repositories that they have. 00:17:41.180 --> 00:17:44.070 align:middle line:84% But feel free to follow along, if you'd like. 00:17:44.070 --> 00:17:46.310 align:middle line:84% So I have what I call Git Seminar, so presumably, 00:17:46.310 --> 00:17:52.850 align:middle line:84% you could be using this folder for keeping track of your final project. 00:17:52.850 --> 00:17:56.040 align:middle line:84% Go ahead, whatever work that you do for your final project. 00:17:56.040 --> 00:17:59.690 align:middle line:90% So let me cd and do git-seminar. 00:17:59.690 --> 00:18:01.010 align:middle line:90% And let's see. 00:18:01.010 --> 00:18:04.190 align:middle line:90% This is currently an empty folder. 00:18:04.190 --> 00:18:08.920 align:middle line:84% So what I'm going to do now is, I'm going to create a file called hello.py 00:18:08.920 --> 00:18:11.640 align:middle line:90% and open that up. 00:18:11.640 --> 00:18:16.020 align:middle line:90% And let's say I do print Hello World. 00:18:16.020 --> 00:18:21.040 align:middle line:90% 00:18:21.040 --> 00:18:24.390 align:middle line:84% So let's say this represents some set of initial changes 00:18:24.390 --> 00:18:26.310 align:middle line:90% that I made to my codebase. 00:18:26.310 --> 00:18:28.590 align:middle line:84% And now I realize, OK, this might be a good point 00:18:28.590 --> 00:18:32.480 align:middle line:84% to stop and save my work, using a commit. 00:18:32.480 --> 00:18:35.570 align:middle line:84% So right now, this codebase is just a directory. 00:18:35.570 --> 00:18:38.480 align:middle line:84% It doesn't have a Git repository associated with it. 00:18:38.480 --> 00:18:40.760 align:middle line:90% So how do I get started? 00:18:40.760 --> 00:18:50.240 align:middle line:84% How do I begin by initializing this repository as a Git repository? 00:18:50.240 --> 00:18:53.120 align:middle line:84% And feel free to send in what you think in the chat. 00:18:53.120 --> 00:18:53.845 align:middle line:90% git init. 00:18:53.845 --> 00:18:54.345 align:middle line:90% Yes. 00:18:54.345 --> 00:18:58.450 align:middle line:90% 00:18:58.450 --> 00:18:59.950 align:middle line:90% OK. 00:18:59.950 --> 00:19:02.050 align:middle line:84% So it says, initialized empty Git repository, 00:19:02.050 --> 00:19:05.250 align:middle line:90% in the folder that I'm in right now. 00:19:05.250 --> 00:19:07.070 align:middle line:84% So before I do anything else, let me just 00:19:07.070 --> 00:19:11.360 align:middle line:84% run git status, which is one of the final commands that we saw. 00:19:11.360 --> 00:19:14.090 align:middle line:84% And this tells me the status of the repository. 00:19:14.090 --> 00:19:16.380 align:middle line:90% It says that there are no commits yet. 00:19:16.380 --> 00:19:21.412 align:middle line:84% And there is one unchecked file called hello.py. 00:19:21.412 --> 00:19:23.620 align:middle line:84% There's also nothing that's been added to the commit, 00:19:23.620 --> 00:19:25.610 align:middle line:84% but untracked files are, in fact, present. 00:19:25.610 --> 00:19:28.990 align:middle line:90% 00:19:28.990 --> 00:19:36.160 align:middle line:84% So now that I have this information, how do I begin by creating a commit? 00:19:36.160 --> 00:19:39.340 align:middle line:84% What do I need to do to actually set up before I can create a commit? 00:19:39.340 --> 00:19:43.090 align:middle line:90% 00:19:43.090 --> 00:19:47.657 align:middle line:84% And in fact, the git status output itself gives you some advice. 00:19:47.657 --> 00:19:48.490 align:middle line:90% You can use git add. 00:19:48.490 --> 00:19:49.810 align:middle line:90% Yes. 00:19:49.810 --> 00:19:51.743 align:middle line:90% So I'm going to do git add. 00:19:51.743 --> 00:19:53.660 align:middle line:84% Now, there are a couple of ways I can do this. 00:19:53.660 --> 00:19:57.940 align:middle line:84% I could do git add hello.py to specify or delegate 00:19:57.940 --> 00:20:01.550 align:middle line:84% that I want to track this one file called hello.py. 00:20:01.550 --> 00:20:04.300 align:middle line:84% But very often, you might have made changes across multiple files, 00:20:04.300 --> 00:20:06.310 align:middle line:84% and maybe you just want to track everything. 00:20:06.310 --> 00:20:08.470 align:middle line:84% And so another thing that you could do is just 00:20:08.470 --> 00:20:12.188 align:middle line:84% git add dot, which would add everything in the current folder. 00:20:12.188 --> 00:20:14.230 align:middle line:84% Dot just refers to the current directory, the one 00:20:14.230 --> 00:20:15.620 align:middle line:90% that you're in right now. 00:20:15.620 --> 00:20:19.590 align:middle line:84% And so git add dot just adds everything in the current directory, all 00:20:19.590 --> 00:20:24.240 align:middle line:84% the untracked changes, into the staging area. 00:20:24.240 --> 00:20:26.950 align:middle line:84% Let me run git status again really quick. 00:20:26.950 --> 00:20:31.530 align:middle line:84% There's still no commits, but now it is tracking this one file called hello.py. 00:20:31.530 --> 00:20:35.110 align:middle line:84% And this is the change that will be committed in the next one. 00:20:35.110 --> 00:20:37.870 align:middle line:84% And so like somebody sent in the chat, the next command 00:20:37.870 --> 00:20:41.840 align:middle line:90% is just git commit -m, commit message. 00:20:41.840 --> 00:20:45.520 align:middle line:90% And so let me say hi. 00:20:45.520 --> 00:20:50.860 align:middle line:84% OK, and doing this commit then returns some output. 00:20:50.860 --> 00:20:54.130 align:middle line:84% These few digits that you see over here are the first few digits 00:20:54.130 --> 00:20:57.370 align:middle line:90% of the commit hash. 00:20:57.370 --> 00:20:59.530 align:middle line:84% And you can see the commit message over here, 00:20:59.530 --> 00:21:04.540 align:middle line:84% the author, and other information about what the changes you made were. 00:21:04.540 --> 00:21:07.480 align:middle line:90% 00:21:07.480 --> 00:21:14.430 align:middle line:84% Let me run git log, just to show you what the output of this looks like. 00:21:14.430 --> 00:21:18.540 align:middle line:84% Git log specifies a list of the previous commits that you made. 00:21:18.540 --> 00:21:22.980 align:middle line:84% Right now, there exists only one commit, and this is the entire commit hash 00:21:22.980 --> 00:21:25.140 align:middle line:90% of that commit that we just made. 00:21:25.140 --> 00:21:27.390 align:middle line:90% This is the commit message, say hi. 00:21:27.390 --> 00:21:30.930 align:middle line:84% And it also specifies the author, their email, the date, and so on. 00:21:30.930 --> 00:21:34.960 align:middle line:90% 00:21:34.960 --> 00:21:35.460 align:middle line:90% OK. 00:21:35.460 --> 00:21:38.220 align:middle line:90% 00:21:38.220 --> 00:21:42.690 align:middle line:84% So that hopefully gives you an idea of how to add in commit, 00:21:42.690 --> 00:21:50.410 align:middle line:84% but now let me try the very last step of saving changes, which is git push. 00:21:50.410 --> 00:21:53.960 align:middle line:84% But if I try to do that, it gives me an error. 00:21:53.960 --> 00:21:54.830 align:middle line:90% It says, fatal. 00:21:54.830 --> 00:21:57.110 align:middle line:90% No configured push destination. 00:21:57.110 --> 00:21:59.270 align:middle line:84% Either specify the URL from the command line, 00:21:59.270 --> 00:22:03.450 align:middle line:84% or configure a remote repository, using git remote add. 00:22:03.450 --> 00:22:06.200 align:middle line:84% So the reason for this is that, so far, everything that we've done 00:22:06.200 --> 00:22:11.360 align:middle line:84% lives entirely on our own device, on our local codebase. 00:22:11.360 --> 00:22:16.140 align:middle line:84% So far, we haven't associated this with anything on GitHub at all. 00:22:16.140 --> 00:22:19.620 align:middle line:84% And so what I'm going to do right now is exactly that. 00:22:19.620 --> 00:22:21.860 align:middle line:84% I'm going to show you to create a GitHub repository 00:22:21.860 --> 00:22:25.160 align:middle line:84% and then associate the two things so that whenever you make commits, 00:22:25.160 --> 00:22:28.230 align:middle line:84% you can then push them to the remote repository. 00:22:28.230 --> 00:22:33.710 align:middle line:84% The main advantage of doing this is that, one, if your own device crashes, 00:22:33.710 --> 00:22:36.210 align:middle line:84% like if you're developing locally, but your device crashes-- 00:22:36.210 --> 00:22:37.840 align:middle line:90% maybe your hard drive fails-- 00:22:37.840 --> 00:22:41.310 align:middle line:84% you will still have a backup of everything stored on GitHub. 00:22:41.310 --> 00:22:43.890 align:middle line:84% And perhaps more importantly, storing it on GitHub 00:22:43.890 --> 00:22:48.100 align:middle line:84% will allow other people, maybe your team members, to look at it. 00:22:48.100 --> 00:22:51.240 align:middle line:84% Or maybe if you're working on an open-source project, maybe somebody 00:22:51.240 --> 00:22:54.540 align:middle line:84% else looking, Googling something, might end up on your repository 00:22:54.540 --> 00:22:58.440 align:middle line:84% and may want to use your code, or download or contribute to it. 00:22:58.440 --> 00:23:01.090 align:middle line:90% 00:23:01.090 --> 00:23:05.010 align:middle line:90% So how do we create a repository? 00:23:05.010 --> 00:23:10.400 align:middle line:84% So just go on to GitHub.com, and again, feel free to follow along if you want. 00:23:10.400 --> 00:23:15.060 align:middle line:84% You should see a New Repository button on the left sidebar, so just click 00:23:15.060 --> 00:23:15.560 align:middle line:90% on that. 00:23:15.560 --> 00:23:20.080 align:middle line:90% 00:23:20.080 --> 00:23:21.890 align:middle line:90% I can specify a repository name. 00:23:21.890 --> 00:23:23.020 align:middle line:90% This can be anything. 00:23:23.020 --> 00:23:26.420 align:middle line:84% In my case, I'm just going to call it git-seminar. 00:23:26.420 --> 00:23:28.670 align:middle line:84% You can choose whether you want to release it publicly 00:23:28.670 --> 00:23:30.860 align:middle line:90% or you want to keep it private. 00:23:30.860 --> 00:23:34.010 align:middle line:90% I will choose private in this case. 00:23:34.010 --> 00:23:36.800 align:middle line:84% And I'm going to leave all of this unchecked, 00:23:36.800 --> 00:23:38.982 align:middle line:84% and I'm going to click Create Repository. 00:23:38.982 --> 00:23:42.760 align:middle line:90% 00:23:42.760 --> 00:23:45.400 align:middle line:90% OK, so now it's created this repository. 00:23:45.400 --> 00:23:47.530 align:middle line:90% You can look at the URL. 00:23:47.530 --> 00:23:51.490 align:middle line:84% It has my username, followed by git-seminar. 00:23:51.490 --> 00:23:54.280 align:middle line:84% And it also provides some setup commands, 00:23:54.280 --> 00:23:58.840 align:middle line:84% which tell you how to link the two repositories together. 00:23:58.840 --> 00:24:01.690 align:middle line:84% And again, there are a couple of ways of doing this, depending on 00:24:01.690 --> 00:24:05.350 align:middle line:84% whether you're creating a new repository or linking an existing one. 00:24:05.350 --> 00:24:07.600 align:middle line:84% In our case, we're just pushing an existing repository 00:24:07.600 --> 00:24:12.040 align:middle line:84% from the command line because we already have a Git repository set up locally. 00:24:12.040 --> 00:24:16.570 align:middle line:84% You would follow these commands if you wanted to start one from scratch, 00:24:16.570 --> 00:24:20.530 align:middle line:84% but in our case, we just need to do these three things. 00:24:20.530 --> 00:24:22.870 align:middle line:84% While you're doing this, make sure you choose the SSH 00:24:22.870 --> 00:24:27.670 align:middle line:84% option if you set up with SSH, which most of you on Codespaces 00:24:27.670 --> 00:24:28.510 align:middle line:90% probably have. 00:24:28.510 --> 00:24:31.165 align:middle line:90% 00:24:31.165 --> 00:24:33.860 align:middle line:84% But the first command that you need to put in 00:24:33.860 --> 00:24:39.200 align:middle line:84% is the command that adds this GitHub URL. 00:24:39.200 --> 00:24:42.200 align:middle line:90% And let me paste that in here. 00:24:42.200 --> 00:24:45.190 align:middle line:90% 00:24:45.190 --> 00:24:49.260 align:middle line:84% So it adds this remote, which I'm calling origin, 00:24:49.260 --> 00:24:52.567 align:middle line:84% and it's linking it to this URL on GitHub, 00:24:52.567 --> 00:24:57.780 align:middle line:84% github.com slash my username slash git-seminar.git. 00:24:57.780 --> 00:25:00.300 align:middle line:84% So now the two repositories have been linked, 00:25:00.300 --> 00:25:03.020 align:middle line:84% and now I can specify the name of the main branch. 00:25:03.020 --> 00:25:06.270 align:middle line:84% And again, we'll talk about branches in a bit, so don't worry about this right 00:25:06.270 --> 00:25:09.040 align:middle line:90% now. 00:25:09.040 --> 00:25:11.790 align:middle line:90% And finally, I can do a git push. 00:25:11.790 --> 00:25:14.880 align:middle line:84% Now, if I just do git push on its own, it again 00:25:14.880 --> 00:25:18.270 align:middle line:84% will complain because GitHub doesn't already know 00:25:18.270 --> 00:25:20.470 align:middle line:90% there exists this branch called main. 00:25:20.470 --> 00:25:22.950 align:middle line:84% And so the very first time that you push, 00:25:22.950 --> 00:25:26.770 align:middle line:90% you'll have to do the set-upstream flag. 00:25:26.770 --> 00:25:30.470 align:middle line:90% You have to use the set-upstream flag. 00:25:30.470 --> 00:25:36.380 align:middle line:84% And so I will copy that in, paste that in, and hit Enter. 00:25:36.380 --> 00:25:38.307 align:middle line:90% And that's about it. 00:25:38.307 --> 00:25:40.640 align:middle line:84% Once it's done pushing, it'll tell you that a new branch 00:25:40.640 --> 00:25:42.290 align:middle line:90% has been created on GitHub. 00:25:42.290 --> 00:25:46.070 align:middle line:84% And this branch has been set up to track this remote branch called main 00:25:46.070 --> 00:25:47.860 align:middle line:90% from origin. 00:25:47.860 --> 00:25:52.940 align:middle line:84% And again, origin is the name of the remote, which is the remote on GitHub. 00:25:52.940 --> 00:25:59.060 align:middle line:84% So let me go back to the GitHub repository and refresh this page. 00:25:59.060 --> 00:26:02.710 align:middle line:84% And now you can see that it looks more familiar, like something that most 00:26:02.710 --> 00:26:04.930 align:middle line:90% GitHub repositories usually look like. 00:26:04.930 --> 00:26:07.150 align:middle line:84% It gives you a list of whatever folders and files 00:26:07.150 --> 00:26:11.480 align:middle line:84% that exist in your repository, along with the commit history. 00:26:11.480 --> 00:26:14.450 align:middle line:84% And so clicking on one commit, for example, will show you 00:26:14.450 --> 00:26:17.070 align:middle line:90% a list of commits that you made so far. 00:26:17.070 --> 00:26:19.280 align:middle line:84% And you can then click on any specific commit 00:26:19.280 --> 00:26:22.835 align:middle line:84% to have a visual representation of the changes that you made. 00:26:22.835 --> 00:26:24.710 align:middle line:84% And in this case, the only change that I made 00:26:24.710 --> 00:26:29.970 align:middle line:84% was to add this one line that says, print Hello World. 00:26:29.970 --> 00:26:31.560 align:middle line:90% And now I can go back to Code. 00:26:31.560 --> 00:26:35.190 align:middle line:84% I can also see I can open up any file and look at the existing 00:26:35.190 --> 00:26:36.690 align:middle line:90% version of that file on GitHub. 00:26:36.690 --> 00:26:44.120 align:middle line:90% 00:26:44.120 --> 00:26:44.620 align:middle line:90% OK. 00:26:44.620 --> 00:26:46.745 align:middle line:84% Again, if you had any questions about that process, 00:26:46.745 --> 00:26:51.712 align:middle line:84% feel free to send it in the chat, and we can go over it in more detail. 00:26:51.712 --> 00:26:59.030 align:middle line:84% BERNIE LONGBOY: So Tarun, one of the questions early on was about-- 00:26:59.030 --> 00:27:04.670 align:middle line:84% although I believe one of our audience-- difference between GitHub and git 00:27:04.670 --> 00:27:06.040 align:middle line:90% clone. 00:27:06.040 --> 00:27:09.290 align:middle line:84% I think you might have mentioned that, if you want to just go over that again? 00:27:09.290 --> 00:27:10.850 align:middle line:90% TARUN PRASAD: Yes. 00:27:10.850 --> 00:27:14.300 align:middle line:84% So I guess I'll talk about the difference between Git and GitHub 00:27:14.300 --> 00:27:15.920 align:middle line:90% first. 00:27:15.920 --> 00:27:20.510 align:middle line:84% Git is a command line tool that lives entirely locally on your device, 00:27:20.510 --> 00:27:23.480 align:middle line:90% or in this case, it's on Codespaces. 00:27:23.480 --> 00:27:27.470 align:middle line:84% So Git is just the name of the command-line tool itself. 00:27:27.470 --> 00:27:31.730 align:middle line:84% And GitHub is essentially the name of a website or a company 00:27:31.730 --> 00:27:34.520 align:middle line:84% which provides some services, which lets you store these Git 00:27:34.520 --> 00:27:38.360 align:middle line:90% repositories on their server. 00:27:38.360 --> 00:27:43.370 align:middle line:84% And so when you do git clone, git clone is a very specific Git command 00:27:43.370 --> 00:27:47.760 align:middle line:84% which lets you download an existing GitHub repository, 00:27:47.760 --> 00:27:53.020 align:middle line:84% because GitHub repositories don't live on your device unless you created them. 00:27:53.020 --> 00:27:59.130 align:middle line:84% So maybe if you wanted to look at the GitHub repository of a classmate, 00:27:59.130 --> 00:28:03.090 align:middle line:84% maybe a classmate has been working on a personal project, 00:28:03.090 --> 00:28:04.680 align:middle line:90% and maybe you want to check it out. 00:28:04.680 --> 00:28:06.430 align:middle line:90% Maybe you want to look at the code. 00:28:06.430 --> 00:28:11.820 align:middle line:84% So what you can do is then is go onto the GitHub.com link, the URL, 00:28:11.820 --> 00:28:17.010 align:middle line:84% and then use git clone along with this URL. 00:28:17.010 --> 00:28:19.890 align:middle line:84% So if you click on the green Code button on GitHub, 00:28:19.890 --> 00:28:23.280 align:middle line:90% it'll specify a URL for the repository. 00:28:23.280 --> 00:28:28.740 align:middle line:90% And again, it's preferable to use SSH. 00:28:28.740 --> 00:28:31.950 align:middle line:84% And you can basically download this, using the command, git clone, 00:28:31.950 --> 00:28:33.600 align:middle line:90% so git clone, followed by the URL. 00:28:33.600 --> 00:28:36.222 align:middle line:90% 00:28:36.222 --> 00:28:37.920 align:middle line:90% BERNIE LONGBOY: OK. 00:28:37.920 --> 00:28:39.810 align:middle line:90% Next question is from Daniel. 00:28:39.810 --> 00:28:42.090 align:middle line:84% Just to be clear, the command line refers 00:28:42.090 --> 00:28:47.640 align:middle line:84% to the Terminal on MacOS and PowerShell on Windows, correct? 00:28:47.640 --> 00:28:48.450 align:middle line:90% TARUN PRASAD: Yes. 00:28:48.450 --> 00:28:52.620 align:middle line:84% On Windows, you can use either PowerShell or Command Prompt. 00:28:52.620 --> 00:28:54.855 align:middle line:90% But on Mac, it is the Terminal, yes. 00:28:54.855 --> 00:28:56.310 align:middle line:90% BERNIE LONGBOY: OK. 00:28:56.310 --> 00:29:00.180 align:middle line:84% And Amy asks, so will our files be saved on our computer and GitHub, 00:29:00.180 --> 00:29:02.438 align:middle line:90% or only on GitHub? 00:29:02.438 --> 00:29:04.480 align:middle line:84% TARUN PRASAD: Yes, that's a really good question. 00:29:04.480 --> 00:29:06.983 align:middle line:84% And again, that brings up the distinction between using-- 00:29:06.983 --> 00:29:07.900 align:middle line:90% BERNIE LONGBOY: Local. 00:29:07.900 --> 00:29:11.100 align:middle line:84% TARUN PRASAD: --git locally and pushing things to GitHub. 00:29:11.100 --> 00:29:14.230 align:middle line:84% So as long as you just do git add and git commit and git add and git 00:29:14.230 --> 00:29:17.880 align:middle line:84% commit and make changes, it's only going to be saved on your computer. 00:29:17.880 --> 00:29:21.120 align:middle line:84% But as soon as you do git push, after you add the remote and the URL 00:29:21.120 --> 00:29:25.470 align:middle line:84% and everything, then all of your changes are going to be pushed to GitHub. 00:29:25.470 --> 00:29:29.496 align:middle line:84% And then it'll be stored on both the local device, your computer, 00:29:29.496 --> 00:29:31.786 align:middle line:90% and on GitHub. 00:29:31.786 --> 00:29:35.280 align:middle line:84% BERNIE LONGBOY: And then this question came up from Austin, 00:29:35.280 --> 00:29:38.640 align:middle line:90% and I believe Anjalee also asked it. 00:29:38.640 --> 00:29:43.020 align:middle line:90% Why SSH and not HTTPS? 00:29:43.020 --> 00:29:45.180 align:middle line:84% TARUN PRASAD: Yeah, also a good question. 00:29:45.180 --> 00:29:52.020 align:middle line:84% So far, I think GitHub has been allowing both HTTPS and SSH as possible ways 00:29:52.020 --> 00:29:55.230 align:middle line:90% of downloading code and authenticating. 00:29:55.230 --> 00:29:57.780 align:middle line:84% So essentially, they're both means of authenticating yourself 00:29:57.780 --> 00:30:00.750 align:middle line:84% to allow you to, for example, push to a repository 00:30:00.750 --> 00:30:03.920 align:middle line:90% or to download a repository and so on. 00:30:03.920 --> 00:30:07.520 align:middle line:84% But recently, I think GitHub has decided for security reasons 00:30:07.520 --> 00:30:09.110 align:middle line:90% to switch entirely to SSH. 00:30:09.110 --> 00:30:14.630 align:middle line:84% It's supposed to be more secure than using HTTPS. 00:30:14.630 --> 00:30:17.720 align:middle line:84% So that's the reason we're also pushing towards SSH these days as well. 00:30:17.720 --> 00:30:38.210 align:middle line:90% 00:30:38.210 --> 00:30:38.710 align:middle line:90% OK. 00:30:38.710 --> 00:30:43.045 align:middle line:84% If there are no other questions, we can continue. 00:30:43.045 --> 00:30:44.185 align:middle line:90% BERNIE LONGBOY: Let's see. 00:30:44.185 --> 00:30:49.470 align:middle line:90% 00:30:49.470 --> 00:30:53.084 align:middle line:90% What is SHH and HTTPS? 00:30:53.084 --> 00:30:55.830 align:middle line:90% 00:30:55.830 --> 00:30:56.700 align:middle line:90% TARUN PRASAD: Yeah. 00:30:56.700 --> 00:30:58.200 align:middle line:90% So SSH and HTTPS-- 00:30:58.200 --> 00:30:59.700 align:middle line:90% I might have mentioned this before-- 00:30:59.700 --> 00:31:02.730 align:middle line:84% are essentially ways of authenticating yourself. 00:31:02.730 --> 00:31:07.380 align:middle line:84% And they specify different protocols for authentication 00:31:07.380 --> 00:31:11.322 align:middle line:84% as well as downloading, and pushing forward, and so on. 00:31:11.322 --> 00:31:14.850 align:middle line:84% BERNIE LONGBOY: And can we just take this last one, 00:31:14.850 --> 00:31:16.840 align:middle line:90% and then we'll go into the next part? 00:31:16.840 --> 00:31:19.120 align:middle line:84% And then I will come back to the questions again. 00:31:19.120 --> 00:31:22.620 align:middle line:84% We could see your first line of code in the first commit. 00:31:22.620 --> 00:31:26.550 align:middle line:84% Did you create the file with no code in it and pushed it, 00:31:26.550 --> 00:31:29.400 align:middle line:90% or with the included line of code? 00:31:29.400 --> 00:31:30.180 align:middle line:90% And that was-- 00:31:30.180 --> 00:31:30.435 align:middle line:90% TARUN PRASAD: So I-- 00:31:30.435 --> 00:31:31.643 align:middle line:90% BERNIE LONGBOY: --from Bruno. 00:31:31.643 --> 00:31:32.940 align:middle line:90% TARUN PRASAD: Yeah. 00:31:32.940 --> 00:31:35.370 align:middle line:84% I created the file, and then included the line of code, 00:31:35.370 --> 00:31:38.110 align:middle line:90% and then pushed the two things together. 00:31:38.110 --> 00:31:40.830 align:middle line:90% And so that was the order I did it in. 00:31:40.830 --> 00:31:43.410 align:middle line:84% I created the file, included the line of code, 00:31:43.410 --> 00:31:46.920 align:middle line:84% then did the whole git add, git commit, git push. 00:31:46.920 --> 00:31:50.580 align:middle line:84% And then that change, the change where I essentially created the file 00:31:50.580 --> 00:31:53.340 align:middle line:84% and added the line of code, was represented on GitHub. 00:31:53.340 --> 00:32:00.940 align:middle line:90% 00:32:00.940 --> 00:32:04.680 align:middle line:90% BERNIE LONGBOY: OK, Tarun. 00:32:04.680 --> 00:32:06.370 align:middle line:90% TARUN PRASAD: OK, awesome. 00:32:06.370 --> 00:32:10.330 align:middle line:84% So let's go on to the next portion of today's seminar. 00:32:10.330 --> 00:32:15.320 align:middle line:84% And this is the main portion which actually focuses on collaboration. 00:32:15.320 --> 00:32:20.900 align:middle line:84% So so far, we've seen that we can save changes, and track changes, and undo 00:32:20.900 --> 00:32:23.393 align:middle line:90% commits, revert changes, and so on. 00:32:23.393 --> 00:32:26.060 align:middle line:84% And that's all well and good when you're the only person working 00:32:26.060 --> 00:32:27.817 align:middle line:90% on your repository. 00:32:27.817 --> 00:32:30.650 align:middle line:84% But in most of your projects, you're probably working with a partner 00:32:30.650 --> 00:32:33.060 align:middle line:90% or with a team member. 00:32:33.060 --> 00:32:36.240 align:middle line:84% And in such cases, it's very useful to know 00:32:36.240 --> 00:32:40.230 align:middle line:84% of ways which will help you collaborate together, 00:32:40.230 --> 00:32:44.860 align:middle line:84% pushing different code to different files, 00:32:44.860 --> 00:32:49.000 align:middle line:84% so even modifying the same lines of code in different ways. 00:32:49.000 --> 00:32:53.710 align:middle line:84% And Git allows you to do all of this in a very seamless way. 00:32:53.710 --> 00:32:57.680 align:middle line:84% The first command that's very useful for this is git pull. 00:32:57.680 --> 00:33:00.290 align:middle line:84% So git pull downloads changes and commits 00:33:00.290 --> 00:33:03.650 align:middle line:84% that have been pushed by others to the remote, 00:33:03.650 --> 00:33:06.820 align:middle line:84% and merges them into your own local repository. 00:33:06.820 --> 00:33:09.570 align:middle line:84% And this is very useful when collaborating with others because you 00:33:09.570 --> 00:33:12.450 align:middle line:90% won't be the only one pushing code. 00:33:12.450 --> 00:33:16.710 align:middle line:84% So for example, let's say you're the one who did the git init, 00:33:16.710 --> 00:33:19.530 align:middle line:84% you made some changes, you added the remote, 00:33:19.530 --> 00:33:23.400 align:middle line:84% you created the GitHub repository, and you push all of your changes. 00:33:23.400 --> 00:33:28.610 align:middle line:84% But in the meanwhile, let's say that your group member 00:33:28.610 --> 00:33:33.080 align:middle line:84% decided to go onto your GitHub URL, your GitHub repository. 00:33:33.080 --> 00:33:36.410 align:middle line:84% They decided to do a git clone, so they downloaded all of the files 00:33:36.410 --> 00:33:39.350 align:middle line:84% that you pushed, and then they made their own changes. 00:33:39.350 --> 00:33:42.500 align:middle line:84% And they also did the whole git add, git commit, git push, 00:33:42.500 --> 00:33:47.720 align:middle line:84% and now their changes have also been pushed into the GitHub repository. 00:33:47.720 --> 00:33:51.890 align:middle line:84% In such a case, GitHub knows about these changes because they pushed it. 00:33:51.890 --> 00:33:55.610 align:middle line:84% But the local version of the code that lives in your device 00:33:55.610 --> 00:33:58.940 align:middle line:84% or that lives on Codespaces doesn't know of those changes 00:33:58.940 --> 00:34:02.040 align:middle line:84% because all of these changes are only on GitHub. 00:34:02.040 --> 00:34:06.630 align:middle line:84% But how do you sync your version of the code, your local version of the code, 00:34:06.630 --> 00:34:08.820 align:middle line:84% with the changes that have been pushed by others? 00:34:08.820 --> 00:34:11.492 align:middle line:90% Well, you use git pull. 00:34:11.492 --> 00:34:13.909 align:middle line:84% So what git pull does is it downloads all of these changes 00:34:13.909 --> 00:34:18.020 align:middle line:84% and then merges them, adds those commits on top of whatever commits you already 00:34:18.020 --> 00:34:21.900 align:middle line:90% made, and then merges them together. 00:34:21.900 --> 00:34:24.679 align:middle line:84% So technically, git pull is actually a combination 00:34:24.679 --> 00:34:29.210 align:middle line:84% of two other commands called a fetch and a merge. 00:34:29.210 --> 00:34:31.610 align:middle line:84% We won't be talking about that in too much detail today, 00:34:31.610 --> 00:34:34.550 align:middle line:84% but do feel free to look that up if you want to learn more about this. 00:34:34.550 --> 00:34:39.110 align:middle line:90% 00:34:39.110 --> 00:34:43.580 align:middle line:84% OK, coming to possibly one of the more important topics and very useful topics 00:34:43.580 --> 00:34:45.907 align:middle line:90% of today's seminar, branches. 00:34:45.907 --> 00:34:48.449 align:middle line:84% And there were some questions earlier about branches as well, 00:34:48.449 --> 00:34:52.540 align:middle line:84% so hopefully this will clear things up a little bit. 00:34:52.540 --> 00:34:55.480 align:middle line:90% So what exactly are branches? 00:34:55.480 --> 00:34:59.650 align:middle line:84% Like in the XKCD comic at the very beginning, it's really pretty simple. 00:34:59.650 --> 00:35:04.390 align:middle line:84% Just think of branches as pointers to commits. 00:35:04.390 --> 00:35:05.520 align:middle line:90% So what does that mean? 00:35:05.520 --> 00:35:09.360 align:middle line:84% I think this illustration will help clear things up a little bit. 00:35:09.360 --> 00:35:13.530 align:middle line:84% Each of these hexadecimal numbers that you see in these white boxes, each 00:35:13.530 --> 00:35:15.780 align:middle line:90% of those represents a commit. 00:35:15.780 --> 00:35:19.600 align:middle line:84% And each commit points to the previous one. 00:35:19.600 --> 00:35:24.630 align:middle line:84% So maybe the 98ca9 commit was made first, and then the 34ac2 commit, 00:35:24.630 --> 00:35:27.735 align:middle line:90% then f30ab, and then 87ab2. 00:35:27.735 --> 00:35:30.440 align:middle line:90% 00:35:30.440 --> 00:35:34.580 align:middle line:84% But you also see these other red boxes, which point at commits. 00:35:34.580 --> 00:35:39.870 align:middle line:84% And these red boxes are essentially what branches are. 00:35:39.870 --> 00:35:42.180 align:middle line:84% In most cases, you'll have some default branch, 00:35:42.180 --> 00:35:44.520 align:middle line:90% usually called something like main. 00:35:44.520 --> 00:35:47.190 align:middle line:84% But you can also create other branches, which 00:35:47.190 --> 00:35:50.280 align:middle line:84% will be very useful when testing experimental features 00:35:50.280 --> 00:35:54.790 align:middle line:84% or when fixing a bug, because you don't want to mess up the main branch. 00:35:54.790 --> 00:35:58.890 align:middle line:84% So for example, if you have a working version on your main branch, which 00:35:58.890 --> 00:36:01.830 align:middle line:84% other people who are also working on this project are using, 00:36:01.830 --> 00:36:07.730 align:middle line:84% then you don't want to push potentially buggy commits onto the main branch. 00:36:07.730 --> 00:36:11.620 align:middle line:84% What you can do instead is create a separate branch. 00:36:11.620 --> 00:36:13.940 align:middle line:84% I will see the commands to do that in a minute. 00:36:13.940 --> 00:36:18.400 align:middle line:84% But you can create a separate branch, commit to that branch, 00:36:18.400 --> 00:36:22.590 align:middle line:84% and then push those commits to that branch on GitHub. 00:36:22.590 --> 00:36:25.180 align:middle line:84% And so the main default branch will be unaffected, 00:36:25.180 --> 00:36:27.137 align:middle line:84% and anybody else can also clone the repository 00:36:27.137 --> 00:36:29.470 align:middle line:84% and pull code and all of that onto their own main branch 00:36:29.470 --> 00:36:31.900 align:middle line:90% without it affecting anything. 00:36:31.900 --> 00:36:34.600 align:middle line:84% But then once you're completely done with your feature, 00:36:34.600 --> 00:36:37.390 align:middle line:84% once you're sure that everything works in your feature branch, 00:36:37.390 --> 00:36:41.230 align:middle line:84% then you can decide to merge it back into the main branch. 00:36:41.230 --> 00:36:44.500 align:middle line:84% And in fact, this is a very common workflow, as we will see in a second 00:36:44.500 --> 00:36:46.080 align:middle line:90% as well. 00:36:46.080 --> 00:36:48.270 align:middle line:84% Any time you work on a big project, especially when 00:36:48.270 --> 00:36:50.152 align:middle line:84% you're collaborating with many other people, 00:36:50.152 --> 00:36:52.110 align:middle line:84% this is a very common workflow that you'll use. 00:36:52.110 --> 00:36:55.240 align:middle line:90% 00:36:55.240 --> 00:37:00.210 align:middle line:84% Now, what are the actual commands to work with branches? 00:37:00.210 --> 00:37:04.510 align:middle line:84% The first one that's very useful is, how do you create a branch. 00:37:04.510 --> 00:37:09.360 align:middle line:84% So for example, let's say I want to create a branch called feature. 00:37:09.360 --> 00:37:13.470 align:middle line:84% Then I can do that by running the command, git branch, 00:37:13.470 --> 00:37:18.490 align:middle line:84% followed by feature or whatever branch name you want to specify. 00:37:18.490 --> 00:37:21.000 align:middle line:84% So git branch feature creates that branch 00:37:21.000 --> 00:37:26.210 align:middle line:84% and makes the branch point to the commit that you're at right now. 00:37:26.210 --> 00:37:29.200 align:middle line:84% So for example, let's say that the latest commit 00:37:29.200 --> 00:37:33.090 align:middle line:90% that I made was this f30ab commit. 00:37:33.090 --> 00:37:36.780 align:middle line:84% And that's what main is pointing at because that's 00:37:36.780 --> 00:37:38.930 align:middle line:90% where the main branch was. 00:37:38.930 --> 00:37:42.470 align:middle line:84% But now, if I create a new branch by using git branch feature, 00:37:42.470 --> 00:37:50.050 align:middle line:84% then feature will also point to f30ab over here. 00:37:50.050 --> 00:37:53.000 align:middle line:84% But any further commits that I make will be associated 00:37:53.000 --> 00:37:55.000 align:middle line:84% with the main branch and not the feature branch, 00:37:55.000 --> 00:37:57.460 align:middle line:84% because git branch doesn't actually change or switch 00:37:57.460 --> 00:38:00.190 align:middle line:90% which branch you're in right now. 00:38:00.190 --> 00:38:02.320 align:middle line:84% If you do want to switch the branch as well, 00:38:02.320 --> 00:38:06.940 align:middle line:84% then you use what's called git checkout, so git checkout with the -b flag, 00:38:06.940 --> 00:38:08.430 align:middle line:90% followed by the branch name. 00:38:08.430 --> 00:38:14.130 align:middle line:84% -b just specifies that you're creating a new branch. 00:38:14.130 --> 00:38:18.030 align:middle line:84% So git checkout, -b, followed by feature, and that'll do the same thing, 00:38:18.030 --> 00:38:19.860 align:middle line:84% but also, any further commits that you make 00:38:19.860 --> 00:38:24.730 align:middle line:84% will be associated with the feature branch and not the main branch. 00:38:24.730 --> 00:38:29.540 align:middle line:84% Once you've created a branch, each time you create a new commit, 00:38:29.540 --> 00:38:33.740 align:middle line:84% the pointer will also advance, along with the commits themselves, 00:38:33.740 --> 00:38:37.477 align:middle line:84% the pointer of whatever branch that you're in right now. 00:38:37.477 --> 00:38:39.310 align:middle line:84% So for example, if I'm in the feature branch 00:38:39.310 --> 00:38:43.300 align:middle line:84% and it's pointing to the f30ab commit, then creating a new commit 00:38:43.300 --> 00:38:46.330 align:middle line:84% will essentially result in what it looks like right now. 00:38:46.330 --> 00:38:50.620 align:middle line:84% It'll create this 87ab2 commit, and then it'll also move the feature branch 00:38:50.620 --> 00:38:53.120 align:middle line:90% to point at the latest commit. 00:38:53.120 --> 00:38:56.058 align:middle line:84% Now, notice that the main branch pointer doesn't actually move, 00:38:56.058 --> 00:38:58.100 align:middle line:84% and that's because you're not in the main branch. 00:38:58.100 --> 00:39:00.470 align:middle line:84% And so if you go back and look at the main branch, 00:39:00.470 --> 00:39:06.200 align:middle line:84% it'll still look exactly like what the repository looked like when you last 00:39:06.200 --> 00:39:08.280 align:middle line:90% made the f30ab commit. 00:39:08.280 --> 00:39:10.297 align:middle line:84% And so the changes in this last 87ab2 commit 00:39:10.297 --> 00:39:12.380 align:middle line:84% will not actually be reflected in the main branch, 00:39:12.380 --> 00:39:16.125 align:middle line:84% and that's exactly what we want because we don't want to mess with the working 00:39:16.125 --> 00:39:17.750 align:middle line:90% version of the code in the main branch. 00:39:17.750 --> 00:39:23.050 align:middle line:90% 00:39:23.050 --> 00:39:25.740 align:middle line:84% You can also switch between branches, using just git checkout 00:39:25.740 --> 00:39:28.327 align:middle line:90% without the -b flag. 00:39:28.327 --> 00:39:30.910 align:middle line:84% And you can just do git checkout, followed by the branch name, 00:39:30.910 --> 00:39:34.850 align:middle line:84% and that'll change the branch you're in right now. 00:39:34.850 --> 00:39:38.150 align:middle line:84% You can also push a new branch to GitHub, 00:39:38.150 --> 00:39:42.350 align:middle line:84% and we saw this earlier with the main branch. 00:39:42.350 --> 00:39:44.150 align:middle line:84% But the way you do it the very first time 00:39:44.150 --> 00:39:47.900 align:middle line:84% is, you use this -u or this set-upstream flag, 00:39:47.900 --> 00:39:51.090 align:middle line:84% which tells GitHub that a new branch is coming in. 00:39:51.090 --> 00:39:54.920 align:middle line:84% And so you can use git push, -u, origin space, the branch name. 00:39:54.920 --> 00:39:57.802 align:middle line:90% 00:39:57.802 --> 00:39:59.760 align:middle line:84% So hopefully that makes sense, but again, we'll 00:39:59.760 --> 00:40:01.890 align:middle line:90% see a demo of this in a bit. 00:40:01.890 --> 00:40:06.108 align:middle line:90% 00:40:06.108 --> 00:40:08.400 align:middle line:84% This is a term that you would have heard of very often, 00:40:08.400 --> 00:40:10.800 align:middle line:84% any time you look at a GitHub repository, 00:40:10.800 --> 00:40:15.515 align:middle line:84% or maybe if you've done an internship in the past, or something like that, 00:40:15.515 --> 00:40:17.356 align:middle line:90% pull requests. 00:40:17.356 --> 00:40:20.030 align:middle line:84% So pull requests are not a Git feature, which 00:40:20.030 --> 00:40:24.120 align:middle line:84% means they're not something that you would work with on the command line. 00:40:24.120 --> 00:40:27.890 align:middle line:84% But rather, they're a feature that's specific to GitHub, but very useful 00:40:27.890 --> 00:40:30.600 align:middle line:90% in collaborative repositories. 00:40:30.600 --> 00:40:34.230 align:middle line:84% And so other remote providers like GitLab or Bitbucket 00:40:34.230 --> 00:40:37.740 align:middle line:84% might also have analogous features, but possibly with different names. 00:40:37.740 --> 00:40:39.570 align:middle line:90% I think GitLab calls it a merge request. 00:40:39.570 --> 00:40:42.140 align:middle line:90% 00:40:42.140 --> 00:40:46.910 align:middle line:84% So a pull request is essentially a request to merge in the changes 00:40:46.910 --> 00:40:50.480 align:middle line:84% that you've pushed to a branch back into the main branch, or any other branch, 00:40:50.480 --> 00:40:53.540 align:middle line:90% but usually the main branch. 00:40:53.540 --> 00:40:57.380 align:middle line:84% So for example, once you've completed the changes 00:40:57.380 --> 00:40:59.480 align:middle line:84% that you want to make in your feature branch, 00:40:59.480 --> 00:41:03.080 align:middle line:84% you can push your feature branch, then go into GitHub, 00:41:03.080 --> 00:41:04.970 align:middle line:90% and you'll see a Pull Request tab. 00:41:04.970 --> 00:41:08.690 align:middle line:84% And over there, you can click on the Create Pull Request button, 00:41:08.690 --> 00:41:11.000 align:middle line:84% and then choose which branch you are merging from 00:41:11.000 --> 00:41:13.620 align:middle line:90% and which branch you're merging into. 00:41:13.620 --> 00:41:16.130 align:middle line:84% And then what that will do is it'll create a request 00:41:16.130 --> 00:41:18.636 align:middle line:90% to merge those changes in. 00:41:18.636 --> 00:41:21.080 align:middle line:84% And so a very common workflow when working in a group 00:41:21.080 --> 00:41:24.800 align:middle line:84% is to always commit to a feature branch and never directly to main, 00:41:24.800 --> 00:41:27.920 align:middle line:84% and then to push the branch to the remote, open up a request, 00:41:27.920 --> 00:41:30.440 align:middle line:84% have somebody else in the team review the pull request, 00:41:30.440 --> 00:41:33.485 align:middle line:84% and either approve it or request changes. 00:41:33.485 --> 00:41:35.360 align:middle line:84% And then once the changes have been approved, 00:41:35.360 --> 00:41:38.540 align:middle line:84% you can then merge it into main, and you can usually do this directly 00:41:38.540 --> 00:41:39.470 align:middle line:90% on GitHub itself. 00:41:39.470 --> 00:41:42.000 align:middle line:90% 00:41:42.000 --> 00:41:45.240 align:middle line:84% And again, we'll see how exactly to do that in a minute. 00:41:45.240 --> 00:41:48.452 align:middle line:90% 00:41:48.452 --> 00:41:50.660 align:middle line:84% BERNIE LONGBOY: Tarun, is this a good break to take-- 00:41:50.660 --> 00:41:50.750 align:middle line:90% TARUN PRASAD: Yeah. 00:41:50.750 --> 00:41:52.876 align:middle line:84% BERNIE LONGBOY: --a couple of questions from the audience? 00:41:52.876 --> 00:41:53.780 align:middle line:90% TARUN PRASAD: Yeah, we can take-- 00:41:53.780 --> 00:41:54.170 align:middle line:90% BERNIE LONGBOY: OK. 00:41:54.170 --> 00:41:54.470 align:middle line:90% TARUN PRASAD: --those questions. 00:41:54.470 --> 00:41:55.553 align:middle line:90% BERNIE LONGBOY: All right. 00:41:55.553 --> 00:41:59.940 align:middle line:84% So, our fantastic audience, I did not forget you here. 00:41:59.940 --> 00:42:03.200 align:middle line:90% So I am going now to-- 00:42:03.200 --> 00:42:05.480 align:middle line:90% let's see. 00:42:05.480 --> 00:42:07.880 align:middle line:90% I think, Leo, we answered yours. 00:42:07.880 --> 00:42:09.500 align:middle line:90% Bruno. 00:42:09.500 --> 00:42:10.910 align:middle line:90% This question comes from Bruno. 00:42:10.910 --> 00:42:14.180 align:middle line:84% I'm trying to use Git in VS Code, but it appears you 00:42:14.180 --> 00:42:16.670 align:middle line:90% are in a repository managed by CS50. 00:42:16.670 --> 00:42:18.300 align:middle line:90% Git is disabled. 00:42:18.300 --> 00:42:21.620 align:middle line:84% So that's not really a question, but the more I think, 00:42:21.620 --> 00:42:24.020 align:middle line:90% is that problem still going on? 00:42:24.020 --> 00:42:24.770 align:middle line:90% TARUN PRASAD: Yes. 00:42:24.770 --> 00:42:27.978 align:middle line:84% If you face that, one thing that I would suggest is just going up one folder, 00:42:27.978 --> 00:42:29.067 align:middle line:90% so maybe using cd.. 00:42:29.067 --> 00:42:31.970 align:middle line:90% 00:42:31.970 --> 00:42:34.560 align:middle line:84% And then you'll be in your workspaces folder. 00:42:34.560 --> 00:42:37.250 align:middle line:84% And then you can essentially create a new folder altogether, 00:42:37.250 --> 00:42:41.048 align:middle line:84% so make something else, like make the project or something. 00:42:41.048 --> 00:42:42.090 align:middle line:90% BERNIE LONGBOY: This is-- 00:42:42.090 --> 00:42:42.290 align:middle line:90% TARUN PRASAD: And once-- 00:42:42.290 --> 00:42:42.380 align:middle line:90% BERNIE LONGBOY: --something else-- 00:42:42.380 --> 00:42:43.010 align:middle line:90% TARUN PRASAD: --you do that-- 00:42:43.010 --> 00:42:44.990 align:middle line:84% BERNIE LONGBOY: --that our students always-- 00:42:44.990 --> 00:42:47.882 align:middle line:90% so it's common, common. 00:42:47.882 --> 00:42:49.290 align:middle line:90% TARUN PRASAD: Yeah. 00:42:49.290 --> 00:42:50.890 align:middle line:90% BERNIE LONGBOY: OK. 00:42:50.890 --> 00:42:51.400 align:middle line:90% Let's see. 00:42:51.400 --> 00:42:52.540 align:middle line:90% What else do we have here? 00:42:52.540 --> 00:42:55.700 align:middle line:90% 00:42:55.700 --> 00:42:56.200 align:middle line:90% Let's see. 00:42:56.200 --> 00:43:02.350 align:middle line:84% From Leo, so is commit 87ab2 just a copy of f30ab 00:43:02.350 --> 00:43:06.400 align:middle line:84% to create a new branch with feature, or are they 00:43:06.400 --> 00:43:09.160 align:middle line:90% actually based on different versions? 00:43:09.160 --> 00:43:11.090 align:middle line:90% TARUN PRASAD: Yeah, good question. 00:43:11.090 --> 00:43:15.410 align:middle line:90% So let me go back to that slide. 00:43:15.410 --> 00:43:19.522 align:middle line:84% So when you create a new branch, there are no new commits that are created. 00:43:19.522 --> 00:43:21.730 align:middle line:84% So the first time that you create the feature branch, 00:43:21.730 --> 00:43:26.120 align:middle line:84% it will still point only at the f30ab, and this 87ab2 commit 00:43:26.120 --> 00:43:28.880 align:middle line:90% doesn't exist yet. 00:43:28.880 --> 00:43:31.730 align:middle line:84% What happens is that if you're on the feature branch, 00:43:31.730 --> 00:43:37.340 align:middle line:84% and you then do a new commit, like you actually make some changes 00:43:37.340 --> 00:43:39.590 align:middle line:84% and you actually do git commit, that's when 00:43:39.590 --> 00:43:42.590 align:middle line:90% this 87ab2 commit might be created. 00:43:42.590 --> 00:43:44.540 align:middle line:84% And then the feature branch moves forward 00:43:44.540 --> 00:43:48.730 align:middle line:84% to point at that commit instead of the original commit. 00:43:48.730 --> 00:43:55.140 align:middle line:84% BERNIE LONGBOY: OK, and this one is just a good one to probably clarify, Tarun. 00:43:55.140 --> 00:43:59.250 align:middle line:84% I did it in a direct message, but it's probably good for the entire audience 00:43:59.250 --> 00:44:02.640 align:middle line:90% to know. git clone is a part of GitHub. 00:44:02.640 --> 00:44:05.340 align:middle line:90% 00:44:05.340 --> 00:44:09.510 align:middle line:84% I believe the question was, do we require an account on git clone, 00:44:09.510 --> 00:44:14.700 align:middle line:84% like we need a GitHub account, or we are just using it online? 00:44:14.700 --> 00:44:18.510 align:middle line:84% So it's really the same account, but I'll let Tarun go ahead 00:44:18.510 --> 00:44:22.125 align:middle line:90% and maybe further elaborate on that one. 00:44:22.125 --> 00:44:22.980 align:middle line:90% TARUN PRASAD: Yeah. 00:44:22.980 --> 00:44:26.700 align:middle line:84% If I understood that question correctly, you 00:44:26.700 --> 00:44:31.920 align:middle line:84% don't generally need a GitHub account to do a git clone. 00:44:31.920 --> 00:44:35.400 align:middle line:84% You should be able to usually just do git clone if it's 00:44:35.400 --> 00:44:38.580 align:middle line:90% a public, open-source repository. 00:44:38.580 --> 00:44:40.830 align:middle line:84% But you may need a GitHub account if you want 00:44:40.830 --> 00:44:44.040 align:middle line:84% to clone a private repository that only you have access to. 00:44:44.040 --> 00:44:47.700 align:middle line:84% Maybe if it's a repository that your project partner created and you decided 00:44:47.700 --> 00:44:54.300 align:middle line:84% to make it private, then you would need to log in, authenticate using GitHub, 00:44:54.300 --> 00:44:58.110 align:middle line:84% and then once you do that, you can then do git clone, whatever URL, 00:44:58.110 --> 00:45:02.450 align:middle line:90% and that should download everything. 00:45:02.450 --> 00:45:05.280 align:middle line:84% Let me know if I didn't answer the question correctly, 00:45:05.280 --> 00:45:07.640 align:middle line:90% but I will try again. 00:45:07.640 --> 00:45:12.909 align:middle line:90% 00:45:12.909 --> 00:45:15.490 align:middle line:84% BERNIE LONGBOY: This question is from Sarah. 00:45:15.490 --> 00:45:19.330 align:middle line:84% Actually, she asks, could you please repeat what branches do? 00:45:19.330 --> 00:45:21.280 align:middle line:90% TARUN PRASAD: Yes, of course. 00:45:21.280 --> 00:45:25.420 align:middle line:84% Branches are one of the more confusing features in Git. 00:45:25.420 --> 00:45:29.470 align:middle line:84% So branches, again, are essentially pointers to commits, 00:45:29.470 --> 00:45:35.340 align:middle line:84% and the point of using branches is to separate different things 00:45:35.340 --> 00:45:37.500 align:middle line:90% that you're working on currently. 00:45:37.500 --> 00:45:40.890 align:middle line:84% So for example, let's say that, simultaneously, you 00:45:40.890 --> 00:45:45.182 align:middle line:84% have some existing working version of your entire codebase. 00:45:45.182 --> 00:45:46.890 align:middle line:84% So let's say you're working on a web app, 00:45:46.890 --> 00:45:49.500 align:middle line:84% and you have some preliminary version ready to go 00:45:49.500 --> 00:45:51.495 align:middle line:90% and working on the main branch. 00:45:51.495 --> 00:45:53.460 align:middle line:84% And you're afraid that any time you push some 00:45:53.460 --> 00:45:57.220 align:middle line:84% commits to that, you might mess it up, things might stop working, 00:45:57.220 --> 00:46:00.940 align:middle line:84% and so don't want to push anything to the main default branch. 00:46:00.940 --> 00:46:08.640 align:middle line:84% So what you can do to get past this is, essentially, create a new branch 00:46:08.640 --> 00:46:11.850 align:middle line:84% and do all of your work in this experimental branch. 00:46:11.850 --> 00:46:16.470 align:middle line:84% So think of this as sort of copy-pasting your entire codebase in a completely 00:46:16.470 --> 00:46:21.810 align:middle line:84% different directory and just messing with whatever 00:46:21.810 --> 00:46:25.380 align:middle line:84% changes that you want to make, whatever box you want to fix in the copied, 00:46:25.380 --> 00:46:26.390 align:middle line:90% duplicate version. 00:46:26.390 --> 00:46:28.140 align:middle line:84% And then, once everything is working, then 00:46:28.140 --> 00:46:31.710 align:middle line:84% you go back to your original directory and copy over the changes. 00:46:31.710 --> 00:46:35.104 align:middle line:84% That's essentially what you're doing with the branches workflow. 00:46:35.104 --> 00:46:37.520 align:middle line:84% BERNIE LONGBOY: And just to keep things moving forward, 00:46:37.520 --> 00:46:41.150 align:middle line:84% I just want to reiterate that we will have a recording available, 00:46:41.150 --> 00:46:45.930 align:middle line:84% so the questions that were answered previously. 00:46:45.930 --> 00:46:46.790 align:middle line:90% And let's see. 00:46:46.790 --> 00:46:50.240 align:middle line:90% 00:46:50.240 --> 00:46:51.260 align:middle line:90% Let's see. 00:46:51.260 --> 00:46:52.580 align:middle line:90% Oh, thanks, Anais. 00:46:52.580 --> 00:46:55.850 align:middle line:90% She just put in a great resource there. 00:46:55.850 --> 00:46:57.422 align:middle line:90% OK. 00:46:57.422 --> 00:46:58.850 align:middle line:90% Tarun, do you want to continue? 00:46:58.850 --> 00:46:59.678 align:middle line:90% We're in our last-- 00:46:59.678 --> 00:47:00.470 align:middle line:90% TARUN PRASAD: Yeah. 00:47:00.470 --> 00:47:01.250 align:middle line:90% BERNIE LONGBOY: --few minutes here. 00:47:01.250 --> 00:47:01.490 align:middle line:90% TARUN PRASAD: Thank you. 00:47:01.490 --> 00:47:03.273 align:middle line:90% We have about 10 minutes left. 00:47:03.273 --> 00:47:06.520 align:middle line:90% 00:47:06.520 --> 00:47:09.190 align:middle line:84% So I'll talk through this very quickly, but because this 00:47:09.190 --> 00:47:12.490 align:middle line:84% is something that many people often have trouble working 00:47:12.490 --> 00:47:14.950 align:middle line:90% with when they're first doing Git. 00:47:14.950 --> 00:47:17.050 align:middle line:84% So usually, when you try to pull code or try 00:47:17.050 --> 00:47:20.780 align:middle line:84% to merge in one branch with another, it will work completely fine, 00:47:20.780 --> 00:47:24.453 align:middle line:84% especially if the changes are in completely different portions 00:47:24.453 --> 00:47:25.120 align:middle line:90% of the codebase. 00:47:25.120 --> 00:47:27.890 align:middle line:84% They're completely different files, for example. 00:47:27.890 --> 00:47:30.710 align:middle line:84% But occasionally, you'll encounter that you've 00:47:30.710 --> 00:47:34.100 align:middle line:84% made some changes to a specific file, but maybe somebody else 00:47:34.100 --> 00:47:37.800 align:middle line:84% has also made some different changes with the same lines in those files, 00:47:37.800 --> 00:47:40.430 align:middle line:90% but in some sort of a different way. 00:47:40.430 --> 00:47:43.810 align:middle line:84% So Git in such cases won't know how to automatically pull the code 00:47:43.810 --> 00:47:45.310 align:middle line:90% or to automatically merge them. 00:47:45.310 --> 00:47:49.280 align:middle line:84% And this results in what's called a merge conflict. 00:47:49.280 --> 00:47:53.240 align:middle line:84% So this is a code sample from, I believe, CS61. 00:47:53.240 --> 00:47:56.060 align:middle line:84% CS61 also has a very useful Git tutorial available 00:47:56.060 --> 00:47:58.980 align:middle line:84% online, so you should definitely check that out, if you can. 00:47:58.980 --> 00:48:00.980 align:middle line:90% And this is a code sample from there. 00:48:00.980 --> 00:48:04.940 align:middle line:84% And you can see that there are two very similar lines over here. 00:48:04.940 --> 00:48:08.180 align:middle line:84% This pointers of i equals malloc of i or 1, 00:48:08.180 --> 00:48:12.280 align:middle line:84% and pointers i equals malloc of i plus 1. 00:48:12.280 --> 00:48:17.860 align:middle line:84% So in particular, the version of the code between these left-angle brackets 00:48:17.860 --> 00:48:20.032 align:middle line:90% and the equals is one version. 00:48:20.032 --> 00:48:22.240 align:middle line:84% And the incoming version is what's between the equals 00:48:22.240 --> 00:48:25.600 align:middle line:84% and the right-angle bracket, so essentially between these two lines 00:48:25.600 --> 00:48:28.240 align:middle line:90% and between these two lines. 00:48:28.240 --> 00:48:30.510 align:middle line:84% And so when you encounter a merge conflict, 00:48:30.510 --> 00:48:33.390 align:middle line:84% it will essentially insert these angle brackets and equals 00:48:33.390 --> 00:48:36.940 align:middle line:84% lines into whatever files have those merge conflicts. 00:48:36.940 --> 00:48:40.050 align:middle line:84% And then it's up to you to manually resolve them. 00:48:40.050 --> 00:48:41.980 align:middle line:84% And how you do that is actually very simple. 00:48:41.980 --> 00:48:45.240 align:middle line:84% You just get rid of these three lines, these three angle-bracket, equals, 00:48:45.240 --> 00:48:46.830 align:middle line:90% angle-bracket lines. 00:48:46.830 --> 00:48:50.118 align:middle line:84% And then you decide which of the two versions of the code to keep, 00:48:50.118 --> 00:48:52.410 align:middle line:84% or in some cases, you might want to merge them together 00:48:52.410 --> 00:48:54.783 align:middle line:90% in some more elaborate way. 00:48:54.783 --> 00:48:57.450 align:middle line:84% And this is usually a good point to talk to the other person who 00:48:57.450 --> 00:49:01.590 align:middle line:84% made the other changes and decide, OK, how exactly should we merge these two 00:49:01.590 --> 00:49:03.840 align:middle line:84% changes together, like why did you make those changes, 00:49:03.840 --> 00:49:05.400 align:middle line:90% why did I make those changes. 00:49:05.400 --> 00:49:08.920 align:middle line:84% Maybe the actual one we want is some sort of a combination of the two. 00:49:08.920 --> 00:49:13.100 align:middle line:90% 00:49:13.100 --> 00:49:16.760 align:middle line:84% And if you're using an editor like VS Code or Codespaces on the browser, 00:49:16.760 --> 00:49:19.970 align:middle line:84% then it should also have very convenient graphical UI 00:49:19.970 --> 00:49:22.290 align:middle line:90% elements that make this even easier. 00:49:22.290 --> 00:49:26.150 align:middle line:84% So it'll show you the changes, using the appropriate colors, green or red, 00:49:26.150 --> 00:49:30.820 align:middle line:84% and then you can choose one or the other, depending on which one you want. 00:49:30.820 --> 00:49:34.260 align:middle line:84% And once the conflicts have been resolved, 00:49:34.260 --> 00:49:36.820 align:middle line:84% just commit your resolved changes, using git commit as usual. 00:49:36.820 --> 00:49:39.960 align:middle line:90% 00:49:39.960 --> 00:49:40.460 align:middle line:90% OK. 00:49:40.460 --> 00:49:44.030 align:middle line:84% Let's very quickly go through a quick demo of this workflow 00:49:44.030 --> 00:49:47.940 align:middle line:84% as well, just so we know what it looks like. 00:49:47.940 --> 00:49:53.490 align:middle line:84% So let's say, hypothetically, I'm going to clear the commands. 00:49:53.490 --> 00:49:56.930 align:middle line:84% So let's say that I'm not the person who made the original commits, 00:49:56.930 --> 00:50:01.110 align:middle line:84% and maybe I'm somebody else in the same group. 00:50:01.110 --> 00:50:02.540 align:middle line:90% So maybe I just did a git clone. 00:50:02.540 --> 00:50:05.900 align:middle line:84% Maybe I just downloaded the entire codebase. 00:50:05.900 --> 00:50:08.720 align:middle line:84% Maybe I do a git log to see the status right now. 00:50:08.720 --> 00:50:11.310 align:middle line:90% I see that it's exactly one commit. 00:50:11.310 --> 00:50:15.240 align:middle line:84% So let's say that I want to push another commit. 00:50:15.240 --> 00:50:20.450 align:middle line:84% So let's, for example, make some changes here. 00:50:20.450 --> 00:50:24.830 align:middle line:84% Before I do that, I don't want to push these changes to the main branch. 00:50:24.830 --> 00:50:31.410 align:middle line:84% And so what I want to do instead is make the changes to some different branch. 00:50:31.410 --> 00:50:37.640 align:middle line:84% So let's say I do git checkout -b, followed by whatever branch name. 00:50:37.640 --> 00:50:41.150 align:middle line:84% In my case, I'm going to call the branch name add-comments. 00:50:41.150 --> 00:50:44.060 align:middle line:90% 00:50:44.060 --> 00:50:47.270 align:middle line:84% So I switched to a new branch called add-comments, and maybe the changes 00:50:47.270 --> 00:50:49.400 align:middle line:84% that I want to make involve just adding a comment. 00:50:49.400 --> 00:50:53.930 align:middle line:90% So maybe I say, say hello. 00:50:53.930 --> 00:50:59.400 align:middle line:84% And now let me run git status, just to show you what the status is right now. 00:50:59.400 --> 00:51:04.060 align:middle line:84% So now I'm on branch add-comments, not on branch main. 00:51:04.060 --> 00:51:06.700 align:middle line:84% And again, I have this modified file, hello.py. 00:51:06.700 --> 00:51:08.560 align:middle line:90% I can do a git add. 00:51:08.560 --> 00:51:12.370 align:middle line:84% I can do a git commit with some commit message, maybe add a comment. 00:51:12.370 --> 00:51:14.880 align:middle line:90% 00:51:14.880 --> 00:51:15.660 align:middle line:90% OK. 00:51:15.660 --> 00:51:18.180 align:middle line:90% And then, finally, I can do a git push. 00:51:18.180 --> 00:51:20.890 align:middle line:84% Now, when I do a git push, again, it's going to give me an error. 00:51:20.890 --> 00:51:23.700 align:middle line:84% It says, no, you'll have to do the set-upstream flag, 00:51:23.700 --> 00:51:33.160 align:middle line:84% so I will use that flag and push it to GitHub. 00:51:33.160 --> 00:51:36.910 align:middle line:84% So let me quickly go into GitHub, and I see here itself, 00:51:36.910 --> 00:51:40.550 align:middle line:84% add-comments had recent pushes less than a minute ago. 00:51:40.550 --> 00:51:44.687 align:middle line:84% And on GitHub, it also prompts me to compare create a pull request. 00:51:44.687 --> 00:51:47.270 align:middle line:84% And that is what I want to do in this case, so let me go ahead 00:51:47.270 --> 00:51:48.140 align:middle line:90% and click on this. 00:51:48.140 --> 00:51:52.570 align:middle line:90% 00:51:52.570 --> 00:51:56.100 align:middle line:84% So I can open a pull request, which is basically a request 00:51:56.100 --> 00:51:59.910 align:middle line:84% to merge in the changes in this branch called add-comments back 00:51:59.910 --> 00:52:01.770 align:middle line:90% into the main branch. 00:52:01.770 --> 00:52:03.508 align:middle line:90% And it says that this is able to merge. 00:52:03.508 --> 00:52:05.550 align:middle line:84% These branches can be automatically merged, which 00:52:05.550 --> 00:52:07.890 align:middle line:90% means there are no merge conflicts. 00:52:07.890 --> 00:52:10.140 align:middle line:90% And on GitHub, I can specify a title. 00:52:10.140 --> 00:52:13.393 align:middle line:84% I can specify any comments, if I have any. 00:52:13.393 --> 00:52:14.935 align:middle line:90% And then I can create a pull request. 00:52:14.935 --> 00:52:17.710 align:middle line:90% 00:52:17.710 --> 00:52:21.530 align:middle line:84% Once I do that-- and this might seem familiar if you've seen your feedback 00:52:21.530 --> 00:52:26.350 align:middle line:84% pull requests in problem sets, because those use pull requests as well-- 00:52:26.350 --> 00:52:29.200 align:middle line:84% I can see in this pull request a list of the commits that 00:52:29.200 --> 00:52:32.830 align:middle line:84% will be merged into the main branch when the merge happens. 00:52:32.830 --> 00:52:35.620 align:middle line:84% And I can also see the changes that have been made. 00:52:35.620 --> 00:52:38.080 align:middle line:84% In this case, there's only one change, the line 00:52:38.080 --> 00:52:41.740 align:middle line:84% highlighted in green, which just adds this comment, saying, say hello. 00:52:41.740 --> 00:52:44.560 align:middle line:90% 00:52:44.560 --> 00:52:48.020 align:middle line:84% Now, hypothetically, I could assign a reviewer for this pull request. 00:52:48.020 --> 00:52:51.878 align:middle line:84% So maybe I want my team members to go through this code 00:52:51.878 --> 00:52:54.670 align:middle line:84% and make sure that everything looks good before it gets merged back 00:52:54.670 --> 00:52:56.420 align:middle line:90% into the main branch. 00:52:56.420 --> 00:52:58.630 align:middle line:84% So if somebody else is also in your group, 00:52:58.630 --> 00:53:01.100 align:middle line:84% you can specify their GitHub username over here. 00:53:01.100 --> 00:53:03.340 align:middle line:90% You can ask them to review it. 00:53:03.340 --> 00:53:07.040 align:middle line:84% And once everything has been reviewed, once everything looks good, 00:53:07.040 --> 00:53:10.340 align:middle line:84% once you've tested everything and it's good to go, 00:53:10.340 --> 00:53:13.900 align:middle line:84% you can then click on the Merge Pull Request button. 00:53:13.900 --> 00:53:19.102 align:middle line:84% And you can optionally add a comment, and you can confirm merge. 00:53:19.102 --> 00:53:21.940 align:middle line:84% So pull request successfully merged and closed. 00:53:21.940 --> 00:53:24.920 align:middle line:84% The add-comments branch can be safely deleted. 00:53:24.920 --> 00:53:27.940 align:middle line:84% So now you no longer need this pointer because the main branch 00:53:27.940 --> 00:53:32.560 align:middle line:84% contains these commits that you added to this add-comments branch. 00:53:32.560 --> 00:53:37.450 align:middle line:84% So I can safely delete this branch, and now if I go back into my main branch 00:53:37.450 --> 00:53:42.403 align:middle line:84% and click on hello.py, I will see the changes over here. 00:53:42.403 --> 00:53:45.570 align:middle line:84% Now, of course, you don't have to go through this entire process of creating 00:53:45.570 --> 00:53:47.910 align:middle line:90% branches and pull requests and so on. 00:53:47.910 --> 00:53:51.153 align:middle line:84% You could technically just directly push everything to the main branch. 00:53:51.153 --> 00:53:53.070 align:middle line:84% But the reason we encourage doing this is just 00:53:53.070 --> 00:53:58.450 align:middle line:84% to ensure that everybody on the team knows exactly what's going on. 00:53:58.450 --> 00:54:00.960 align:middle line:84% And you also have this whole process of code review, 00:54:00.960 --> 00:54:03.168 align:middle line:84% where different people look at the code and make sure 00:54:03.168 --> 00:54:06.780 align:middle line:84% that everything is good to go before you merge it into the main branch, which 00:54:06.780 --> 00:54:09.824 align:middle line:90% contains the working version. 00:54:09.824 --> 00:54:14.020 align:middle line:84% BERNIE LONGBOY: OK, and Tarun, we're in our last four minutes 00:54:14.020 --> 00:54:18.520 align:middle line:84% here, so if we have other questions or comments. 00:54:18.520 --> 00:54:23.060 align:middle line:90% 00:54:23.060 --> 00:54:24.700 align:middle line:90% Here's one from Jim. 00:54:24.700 --> 00:54:29.740 align:middle line:84% If a merge is done to the main branch and a bug is discovered later, 00:54:29.740 --> 00:54:33.010 align:middle line:84% what is the best way to handle the bug fix? 00:54:33.010 --> 00:54:36.880 align:middle line:84% TARUN PRASAD: Yeah, that's a really good question. 00:54:36.880 --> 00:54:41.050 align:middle line:84% So there are a few ways of handling bug fixes. 00:54:41.050 --> 00:54:46.030 align:middle line:84% If it's something that you want to undo, like maybe it's one very specific buggy 00:54:46.030 --> 00:54:48.790 align:middle line:84% commit that you want to undo, you can then 00:54:48.790 --> 00:54:50.890 align:middle line:90% use git revert, like we saw earlier. 00:54:50.890 --> 00:54:55.690 align:middle line:84% You can do git revert, followed by the commit hash of the buggy commit. 00:54:55.690 --> 00:55:00.160 align:middle line:84% And then you can then push those changes back into the main branch. 00:55:00.160 --> 00:55:04.930 align:middle line:84% If it's more detailed than that, maybe it's more specific. 00:55:04.930 --> 00:55:08.050 align:middle line:84% Maybe a bunch of commits are all buggy, or maybe you 00:55:08.050 --> 00:55:10.060 align:middle line:84% want to completely get rid of the history 00:55:10.060 --> 00:55:12.850 align:middle line:90% of the existence of that commit itself. 00:55:12.850 --> 00:55:16.090 align:middle line:84% There are ways of doing that as well, which we don't quite have time 00:55:16.090 --> 00:55:19.930 align:middle line:84% to go through now, but I'll just send over a couple of commands 00:55:19.930 --> 00:55:27.250 align:middle line:84% that you can look at, that you can definitely look up, 00:55:27.250 --> 00:55:30.340 align:middle line:84% and you can learn more about exactly how to work with these. 00:55:30.340 --> 00:55:34.660 align:middle line:84% Two of them that'll be very useful include git reset and git rebase 00:55:34.660 --> 00:55:37.900 align:middle line:84% -i, which is something called an interactive rebase. 00:55:37.900 --> 00:55:42.516 align:middle line:84% And yeah, those should help you learn more about this. 00:55:42.516 --> 00:55:46.860 align:middle line:84% BERNIE LONGBOY: What are your thoughts on GitHub Desktop App? 00:55:46.860 --> 00:55:49.090 align:middle line:84% TARUN PRASAD: That's also a good question. 00:55:49.090 --> 00:55:51.430 align:middle line:84% Lots of people find it very useful, especially when 00:55:51.430 --> 00:55:55.720 align:middle line:90% you first start using or learning Git. 00:55:55.720 --> 00:55:57.970 align:middle line:84% I personally wouldn't recommend it, just because I 00:55:57.970 --> 00:56:00.640 align:middle line:84% think it's very useful to learn the commands themselves, 00:56:00.640 --> 00:56:05.410 align:middle line:84% because that's what lets you understand, or it gives you 00:56:05.410 --> 00:56:07.483 align:middle line:90% the full power of what Git can do. 00:56:07.483 --> 00:56:10.150 align:middle line:84% But having said that, you can definitely download GitHub Desktop 00:56:10.150 --> 00:56:13.000 align:middle line:84% and use that for making a lot of this easier, because then you 00:56:13.000 --> 00:56:14.500 align:middle line:90% don't have to remember the commands. 00:56:14.500 --> 00:56:17.620 align:middle line:84% You can just click on the Add button and the Commit button, 00:56:17.620 --> 00:56:19.810 align:middle line:90% and that definitely makes things easier. 00:56:19.810 --> 00:56:21.490 align:middle line:90% BERNIE LONGBOY: OK, last two. 00:56:21.490 --> 00:56:23.680 align:middle line:90% One's a comment, and a question. 00:56:23.680 --> 00:56:26.500 align:middle line:90% Is it considered best practice to-- 00:56:26.500 --> 00:56:27.580 align:middle line:90% oops. 00:56:27.580 --> 00:56:30.730 align:middle line:84% Is it considered best practice to make our comments in code 00:56:30.730 --> 00:56:36.070 align:middle line:84% and pull merge requests in present tense, rather than past tense, i.e. 00:56:36.070 --> 00:56:39.040 align:middle line:90% add a comment versus added a comment? 00:56:39.040 --> 00:56:41.920 align:middle line:84% TARUN PRASAD: Yeah, also a really good question, and different people 00:56:41.920 --> 00:56:44.950 align:middle line:84% have very different conventions for this. 00:56:44.950 --> 00:56:48.370 align:middle line:84% I personally use present tense, like add a comment, 00:56:48.370 --> 00:56:51.460 align:middle line:84% because one way of thinking about commits is, 00:56:51.460 --> 00:56:53.530 align:middle line:84% rather than what you did in the past, you 00:56:53.530 --> 00:56:56.440 align:middle line:84% can think of a commit as what are the changes that will 00:56:56.440 --> 00:56:58.960 align:middle line:90% be made when you apply this commit. 00:56:58.960 --> 00:57:01.720 align:middle line:84% So when I apply this commit, it adds this comment, 00:57:01.720 --> 00:57:04.570 align:middle line:84% and so you can write the message in present tense. 00:57:04.570 --> 00:57:07.750 align:middle line:84% But of course, different people have very different opinions on this, 00:57:07.750 --> 00:57:09.475 align:middle line:90% and there's no one right answer. 00:57:09.475 --> 00:57:10.210 align:middle line:90% BERNIE LONGBOY: Thanks, Tarun. 00:57:10.210 --> 00:57:11.002 align:middle line:90% TARUN PRASAD: Yeah. 00:57:11.002 --> 00:57:12.180 align:middle line:90% Thank you all for coming. 00:57:12.180 --> 00:57:13.000 align:middle line:90%