1 00:00:06,163 --> 00:00:09,210 - All right, let's talk about some common usage 2 00:00:09,210 --> 00:00:11,520 of Git repositories. 3 00:00:11,520 --> 00:00:13,980 First is a basic repository usage, 4 00:00:13,980 --> 00:00:17,640 where you can use git clone on your Git repository 5 00:00:17,640 --> 00:00:20,160 to clone the contents of any remote repository 6 00:00:20,160 --> 00:00:21,243 to your computer. 7 00:00:22,380 --> 00:00:23,370 And if you have done that, 8 00:00:23,370 --> 00:00:26,460 and ever you need to fetch the latest changes, 9 00:00:26,460 --> 00:00:30,150 you can use git pull from within that Git repository. 10 00:00:30,150 --> 00:00:31,140 That's pretty easy. 11 00:00:31,140 --> 00:00:33,450 You've probably done it before. 12 00:00:33,450 --> 00:00:36,570 Now, how do we upload changed files? 13 00:00:36,570 --> 00:00:40,320 Well, modified files need to go through the staging process. 14 00:00:40,320 --> 00:00:43,500 So after changing files, you should use git status 15 00:00:43,500 --> 00:00:45,720 to see which files have changed. 16 00:00:45,720 --> 00:00:48,090 Next, you can use git add to add these files 17 00:00:48,090 --> 00:00:52,410 to the staging area or git rm to remove the files. 18 00:00:52,410 --> 00:00:55,495 And then you commit the changes, no matter if it's a change. 19 00:00:55,495 --> 00:00:58,380 And then you commit the changes, no matter 20 00:00:58,380 --> 00:01:00,150 if you've added files or removed files 21 00:01:00,150 --> 00:01:03,483 using git commit minus m followed by your commit methods. 22 00:01:04,530 --> 00:01:08,220 Next, you synchronize, git push origin main, for instance. 23 00:01:08,220 --> 00:01:10,380 And then from any client you can use git pull 24 00:01:10,380 --> 00:01:12,210 to update your current Git clone 25 00:01:12,210 --> 00:01:15,383 and make sure that you are completely up to date. 26 00:01:15,383 --> 00:01:18,570 Now, sometimes you may have removed the file 27 00:01:18,570 --> 00:01:19,770 and you regret. 28 00:01:19,770 --> 00:01:22,560 Well, then Git is offering a couple of options 29 00:01:22,560 --> 00:01:23,493 to get it back. 30 00:01:24,450 --> 00:01:27,090 Let's have a look at the simple option. 31 00:01:27,090 --> 00:01:29,850 So your ability to undo a change really depends 32 00:01:29,850 --> 00:01:31,900 on the current state of the modification. 33 00:01:33,030 --> 00:01:36,540 If the file is staged but not yet committed, it's very easy. 34 00:01:36,540 --> 00:01:38,790 Use git restore minus minus staged 35 00:01:38,790 --> 00:01:41,490 followed by the file name. 36 00:01:41,490 --> 00:01:44,880 So first, if you have used git rm myfile and git status, 37 00:01:44,880 --> 00:01:46,590 you will see it as removed, 38 00:01:46,590 --> 00:01:49,230 and if then you think "oh no I want to have it back," 39 00:01:49,230 --> 00:01:51,150 git restore minus minus staged 40 00:01:51,150 --> 00:01:52,473 is going to do it for you. 41 00:01:55,470 --> 00:01:58,170 If a file has already been committed and pushed, 42 00:01:58,170 --> 00:01:59,490 you can use git log 43 00:01:59,490 --> 00:02:02,790 and identify the commit by the commit message. 44 00:02:02,790 --> 00:02:05,940 And next, use the commit hash to revert the transaction 45 00:02:05,940 --> 00:02:08,790 using git checkout followed by the hash id, 46 00:02:08,790 --> 00:02:10,230 followed by the file name. 47 00:02:10,230 --> 00:02:14,370 And that will allow you to get this one single file back. 48 00:02:14,370 --> 00:02:16,590 If you do that, it's really important that you 49 00:02:16,590 --> 00:02:20,730 revert to the latest commit where you still had the file. 50 00:02:20,730 --> 00:02:23,070 So you really need to pay attention. 51 00:02:23,070 --> 00:02:24,213 Let me demonstrate. 52 00:02:30,420 --> 00:02:33,930 So, here we have my new git repo and in my new git repo 53 00:02:33,930 --> 00:02:37,170 I'm going to remove 10 dot txt. 54 00:02:37,170 --> 00:02:40,053 So, git rm 10 dot txt. 55 00:02:41,790 --> 00:02:44,610 Let's choose git status to figure out what is happening. 56 00:02:44,610 --> 00:02:47,790 And there we can see it's deleted 10 dot txt 57 00:02:47,790 --> 00:02:51,262 and it's telling us git restore minus minus staged, 58 00:02:51,262 --> 00:02:55,980 which we can use to unstage, to get it back, 59 00:02:55,980 --> 00:02:58,710 but I don't want to get it back yet. 60 00:02:58,710 --> 00:03:03,027 So I'm using git commit minus m remove 10, 61 00:03:07,470 --> 00:03:09,850 and then I'm using git push 62 00:03:12,750 --> 00:03:14,400 and oh no, what did I do? 63 00:03:14,400 --> 00:03:15,540 I need to have it back. 64 00:03:15,540 --> 00:03:17,290 Well, what are we going to do to get it back? 65 00:03:17,290 --> 00:03:21,993 Well, git log minus minus 10 dot txt. 66 00:03:23,520 --> 00:03:25,590 This git log is giving an overview 67 00:03:25,590 --> 00:03:28,860 of all the transactions that have happened on 10 dot txt. 68 00:03:28,860 --> 00:03:32,640 And now we can see that there are two different commits. 69 00:03:32,640 --> 00:03:34,440 This is the one where we removed it. 70 00:03:34,440 --> 00:03:37,050 This is the one where we created it. 71 00:03:37,050 --> 00:03:42,000 So I'm going to use a commit ID and git checkouts followed 72 00:03:42,000 --> 00:03:43,390 by this commit ID 73 00:03:44,730 --> 00:03:49,285 followed by 10 dot txt. 74 00:03:49,285 --> 00:03:50,370 And what is the result? 75 00:03:50,370 --> 00:03:53,553 Well, the result is that I have my 10 dot txt back. 76 00:03:55,290 --> 00:03:56,760 Are we there yet? 77 00:03:56,760 --> 00:03:59,880 Well, no, not exactly, because we have the file 78 00:03:59,880 --> 00:04:02,850 still being ready to be committed. 79 00:04:02,850 --> 00:04:07,590 So I need to git add 10 dot txt. 80 00:04:07,590 --> 00:04:08,910 Did I really need to do that? 81 00:04:08,910 --> 00:04:11,910 No, I don't even need to do that because it's already there. 82 00:04:11,910 --> 00:04:14,824 I need to git commit minus m, 83 00:04:14,824 --> 00:04:16,263 10 back, 84 00:04:18,540 --> 00:04:19,683 and git push. 85 00:04:22,110 --> 00:04:24,990 And now we have restored this file 10 dot txt back 86 00:04:24,990 --> 00:04:26,850 and I have it permanently back. 87 00:04:26,850 --> 00:04:30,150 So that's how you can undo certain transactions. 88 00:04:30,150 --> 00:04:31,400 Now what else can you do? 89 00:04:33,810 --> 00:04:36,837 Another convenient thing is dot gitignore. 90 00:04:36,837 --> 00:04:39,484 In some cases, a directory may have files 91 00:04:39,484 --> 00:04:43,050 that you don't want to be cloned to the GIT repository. 92 00:04:43,050 --> 00:04:45,540 Think about files that contains sensitive values, 93 00:04:45,540 --> 00:04:46,890 like passwords. 94 00:04:46,890 --> 00:04:50,010 Hey, before we continue, can I say one thing about it? 95 00:04:50,010 --> 00:04:52,710 I think if it contains sensitive values, 96 00:04:52,710 --> 00:04:55,890 it shouldn't be in your git directory in the first place. 97 00:04:55,890 --> 00:04:59,190 That reduces the risk of anything going wrong. 98 00:04:59,190 --> 00:05:02,160 So better go for strict separation. 99 00:05:02,160 --> 00:05:04,080 But hey, if you don't wanna do that, 100 00:05:04,080 --> 00:05:07,440 it's useful to know that you can use dot gitignore 101 00:05:07,440 --> 00:05:09,990 So, if you want to exclude files from being synchronized, 102 00:05:09,990 --> 00:05:13,260 you can create a text file with name dot gitignore, 103 00:05:13,260 --> 00:05:15,663 that lists all files that need to be ignored. 104 00:05:16,500 --> 00:05:18,390 A dot gitignore file can be added 105 00:05:18,390 --> 00:05:20,550 to the current git product directory 106 00:05:20,550 --> 00:05:24,929 and you can use the following command to create it. 107 00:05:24,929 --> 00:05:28,320 So git conflict minus minus global core excludesfile 108 00:05:28,320 --> 00:05:32,670 dot gitignore underscore global. 109 00:05:32,670 --> 00:05:33,900 And in this list, 110 00:05:33,900 --> 00:05:35,580 you can list files that should be ignored 111 00:05:35,580 --> 00:05:38,100 if they occur in any Git repository. 112 00:05:38,100 --> 00:05:39,510 So you can do it globally. 113 00:05:39,510 --> 00:05:43,050 You can also do it in a local Git repository. 114 00:05:43,050 --> 00:05:45,350 And that is what I want to show you right now. 115 00:05:47,430 --> 00:05:49,530 So let me use echo password. 116 00:05:49,530 --> 00:05:53,133 Right, then password dot txt. 117 00:05:55,830 --> 00:05:57,003 That's a typo. 118 00:06:00,810 --> 00:06:05,810 And let me echo password dot txt greater than dot gitignore. 119 00:06:11,969 --> 00:06:13,887 Now I'm using git add star, 120 00:06:16,020 --> 00:06:17,790 and oh what do we see? 121 00:06:17,790 --> 00:06:21,330 We see following paths are ignored. 122 00:06:21,330 --> 00:06:23,550 It's going to display this message all the time. 123 00:06:23,550 --> 00:06:24,540 If you don't wanna see that, 124 00:06:24,540 --> 00:06:28,770 then you can use git config advice add ignored file false. 125 00:06:28,770 --> 00:06:30,900 Then you won't see the message anymore, 126 00:06:30,900 --> 00:06:34,440 but for now I'm good. 127 00:06:34,440 --> 00:06:39,330 So git status is just telling us 128 00:06:39,330 --> 00:06:42,480 that there is this gitignore file and this gitignore file 129 00:06:42,480 --> 00:06:44,970 is an ignored file. 130 00:06:44,970 --> 00:06:49,970 And git commit minus m ignoreme is making sure 131 00:06:51,690 --> 00:06:53,940 that we are doing the commit and oh, 132 00:06:53,940 --> 00:06:55,740 we already have to branch up to date. 133 00:06:55,740 --> 00:06:56,910 What does that mean? 134 00:06:56,910 --> 00:06:59,610 Well, that means that if I'm going to check 135 00:06:59,610 --> 00:07:02,280 in the Git repository on the website, 136 00:07:02,280 --> 00:07:05,670 I won't see the password dot txt file. 137 00:07:05,670 --> 00:07:07,020 That's all that it's about. 138 00:07:08,340 --> 00:07:10,230 So this hopefully helps you 139 00:07:10,230 --> 00:07:12,990 in working in a more efficient way with Git. 140 00:07:12,990 --> 00:07:15,270 There's one major topic we still need to talk about 141 00:07:15,270 --> 00:07:16,440 and that's branches. 142 00:07:16,440 --> 00:07:18,040 Let's do that in the next video.