YTread Logo
YTread Logo

Git 101 Basics - Computer Stuff They Didn't Teach You #4

Jun 03, 2021
Hello friends, I'm Scott Hanselman. I hope you have subscribed to my channel and also leave me comments about the kinds of things you would like to learn. I have been doing

computer

s and programming for about 30 years professionally and about 40 years. If you don't count on getting paid for it, I don't know everything, but I know a lot of little things. I am a kind of Swiss army knife. If there is something you want to learn or something that can help you learn, please leave it. Get to know me and I'll make a little video about it.
git 101 basics   computer stuff they didn t teach you 4
This one here I thought it would be fun if we talked about Get. Now there are so many great tutorials and videos and full classes. I really don't like the way

they

express themselves. there are a lot of confusing diagrams and branches so I thought I'd do it. I got

basics

for normal people. Assume a few things and let's do this. Let's go to image and image and talk about some of the assumptions, so first thing is. I am now using Windows. You can certainly use a Mac if you want. I am using windows terminal. Your terminal or command prompt may look a little different like this.
git 101 basics   computer stuff they didn t teach you 4

More Interesting Facts About,

git 101 basics computer stuff they didn t teach you 4...

Alright. I recommend you get the Windows terminal. I also recommend that you go to my blog and search for Windows Terminal pretty quickly and what a nice message means is that it is an accessory that has information. I want to point out that not only does it have the path, but it has some pretty colors and it gives you information about get which I'm going to show you shows your name the name of your

computer

this will only take you five or ten minutes to set up it will add a lot to your get experience You'll also I would recommend that you get visual studio code which is this application here on the right, so I have the Windows terminal here on the left and I have the Visual Studio code right here.
git 101 basics   computer stuff they didn t teach you 4
I'm going to close both and start again. I'm going to open the Windows terminal. I'm using PowerShell for what I'm doing here, everything is explained in the post in a nice message. I'm going to go to my D drive and I have a folder called github, I have another folder called learning git and you. I'll notice when I go in there, my nice message immediately says "Hello, what does it mean, you might see master, I like to use me, you can also see the trunk, those are your initial branch, it's like a family tree and the main branch is the grandparent type." of everything and we will see how the branches work in a moment in this folder by type dir there is nothing.
git 101 basics   computer stuff they didn t teach you 4
I can also type the start point and I can open Windows Explorer and see that there is nothing there either. Getting back to that, I have the Visual Studio code, so I'm going to write the code dot where dot is the current folder. Remember we're in the folder called D github learning to get when I say code dot, Visual Studio will open and

they

Could give me a little welcome. I'll close that and you'll see nothing here. Okay, this is important because one of the things he does and does very well is he tries to lie to you, he lies to you to improve your life. make your life easier now not all lies are bad in this case what it's doing is hiding things why this folder is a git repository a place for my source control if I upload a folder you'll see how it doesn't say main if I go back to one folder, it says main, so there must be something special in this empty folder, well if I click on windows explorer in view and click on hidden items, there is a hidden folder here called dot, but traditionally if a folder has a dot in front of it means it is now hidden from you.
If we open it up, we can see that there are a lot of things here. Don't touch any of this, you'll ruin it. This is basically all that git is. hiding from you it's your changes database it's your repository it's the secret sauce that makes it work never ever go into that folder just acknowledge that it's a friendly lie I'm going to hide that and let it lie to me now I'm going to go and use the Windows keys and I'll say Windows left arrow and then Windows right arrow, so I have here on the right my empty folder and on the left I'm going to clear my screen of my empty folder.
So this is a way of thinking about my files where I have the graphical information on one side and I have the command line or terminal version on the other side. Now I can use any editor. I can use Visual Studio code. I can use notepad. whatever makes me happy and I might say something like notepad test dot txt this is not Visual Studio code this is something super basic and I'll say test dot text and notepad says hey I don't know what that is, I've never heard of that and I'll say yes I'll say this is a test this is my first test and I'll save it and you can see it's there so there's a file you can see when it was created you can see it's real and then it exists , okay, I'm going to close it and press Enter right here and you'll notice something interesting just happened.
My message on my terminal, this nice personalized message that I asked you to set up. Change to color. It's not green. It's already yellow and says Hello, an item was added, no items were changed, and nothing was deleted. Remember how we said this is a magic folder, there is a hidden folder there, that folder dot git noticed something was added but if I make a change to that file another test nothing really happened there it

didn

't do anything it's because we

didn

't tell it anything about that I can't go back to a previous version I can't rewind time because nothing has changed okay, nothing interesting has happened Apart from the fact that something was noticed there, that's interesting at the moment, that is, there is a modified repository with a file, but I haven't done anything I haven't said, so let's see how we can tell git what's going on.
I can say git status now, git is the command I'm typing here that was installed when I went to the git website and installed get for my system. I have Windows, you might have Mac or Linux and that's fine. say get status and it says hey, I want a branch called main or master or trunk. I don't have any confirmation. I haven't told you anything, but I have some files that no one tracked and I mean they're there, but they're not being tracked. I'm not keeping an eye on them for you, so there's really nothing added to confirm, but just to remind you again that there are untracked files present, so you know, use git add to track them. exit, ok, get add and I want to press tab get add I just hit the tab key on my keyboard and that meant I didn't have to type test point text.
Great, what happened here is very subtle, but our little message changed from saying hey, something important happened to everything. right, something was modified, notice it's the same icon that we saw here that icon modified, nothing was modified, nothing was removed, one was added, but our repository was modified, okay, let's do it again, get the status, great, we're in the branch, there are no commits yet. I haven't really told myself anything, but you're setting things up to commit, you put a file there, this is called staging, you've put a file ready to be committed in stages, but we have, we're kind of preparing for a confirmation, but we haven't done it yet.
You could add another notepad test file. Hey, this is another file notice on the right side. It just appeared. Well, that's interesting. Look at this. There are two. These things, what's going on, well, here's a file that we're ready to send and then there's this other one, remember that warning, hey, something's happening, there's another file that's kind of sitting around, if I say get status, we say that It's okay, I'm ready. to go ahead with this, ready to tell everyone, commit it, put it in the database, but you know there really is an untracked file here, I just want to let you know that there are two files in this folder, one that I know about and one that I don't.
I'm going to add that one too when I say git add test2 there we go, so now I have two cool files ready to go, so now let's commit them. I'm going to say git commit and you have to tell the system what. If you think about that, you have to give it a message to acknowledge and give information about that confirmation. I want to batch these files and I'm going to say git commit. Hey, these are my first two files. Okay, when I press Enter, great, okay. Well, two files are changed, there's something called insertion, it's a number of lines, don't worry too much about it, but the fact is we add two files and look, we're back to green, that's great, that means everything is great, I have two files here, okay, what happens if I accidentally delete these files?
Oops, they're gone. I hit enter like, whoa, whoa, what's going on. Two files are missing. That's not, that's not good. Well, I guess you meant to do it right. some changes, I assume you want to prepare them and let me know that you deleted these two files, so how can we do something about it? you want to add them and tell people that you compromised these files, deleted them, intended to delete them or do you want to put them back? Well, shoot, that was an accident. I'm going to say git recovery try that text look at the right side and get restore try colon txt they're back they're back I didn't mean to do that and I'm back in a good place I get the status okay cool that's it it's good, I can say git log and I can see there's a ledger, there's a log, there's an audit log and I can go see, look Scott Hanselman, that's I went and did something and I went and added some files a time and that weird delete is going to pretend that that didn't even happen, okay, we just put it back to how it was now, let's switch to Visual Studio code.
I'm going to use the Visual Studio code on the right instead of using Explorer because the Visual Studio code will allow me to edit my files so I can see the folder here and I can make my changes at the same time and I can see the perspective of it. about what's going on with this little icon here, this little icon here says source control, you'll see source control referred to as a family tree or a series of branches, so that's what that icon means. I'll worry about this icon and this icon. Okay, I also want to point out the name of my branch here.
We'll go over it in a few minutes so you can see the changes on the left in our terminal and what's reflected on the right side. The Studio code is aligned, so let's take a look, make some changes. Hey, hey, I forgot a line, here we go, great, so look on the right side. The Visual Studio code says M, which means modified, you made a change. cool press enter here a file has been modified that makes sense here is a line in another file save cool look two files have been modified press enter here in my terminal actually two files have been modified now let's say get add and I'm going to say doc, remember, earlier we said code dot in the current directory or we said start dot to open Explorer.
I'll say add dot and now I've prepared, I told get that I modified two files and Now I'm going to go and commit them. Get the commitment. I made some changes. I added two lines. Alright. Brilliant. Two files changed. That's great. These are no longer modified here. Nothing happens here. We'll come back to that in a second. I'm going to say git log great, so now what we're doing here is we're pointing to the header and the header is pointing to the most recent change here that says I think we can split this so we can see one. file at the top and one file at the bottom, so I'll right click and split, so here we go, we have tests at the top, test two at the bottom.
I have the files here, everything is visible. on the screen at the same time, I'll even make a little bit of space so you can see that in case you got my head in the way, okay, get the blog, we saw it, okay, what if I needed this? This hash is a unique identifier. that's the ID, the social security number, the unique number that represents this previous commitment, so I can go and check it. I could go back in time if I wanted and I could get something specific. You might say, let's have some. of that enough to be unique, what if I said you take a look, okay and this is a little strange.
I just went back in time, look at this look on the right side, everything went back to the way it was, we just went back in time, okay? but when we did that, now we're separated, we can look around, but we're not actually at the right time, we've gone back in time to an alternate universe, okay, then I'll go and say "pay principal" and I'll come back to change, so look at the right side, look at those files. I'm going to do that again, let's do it again, so we're here, we're on the current home page, this is the state of things on the right side.
I'm going to say git log and I'm going to say look, you know, I want to go back to four minutes ago. I have a unique ID that represents four minutes ago, let's go back and look at the right side. I'm going to press enter and I want to You have to look here one, they're gone, they've changed, we've gone back in time and we can mess around here if we wanted to, but I want to go ahead and go back to the main page, okay, normally that's not the way in which you want to do it. work what you would like to do is not simply going back in time what you want to do is divide time in half you want to branch out you know thatI'm working on this but I have an idea that I'm going to practice.
I'm going to move over here to this parallel universe and see if this is a good universe that I can spend time in, so I'll say "pay" and what I want to do is make a new branch of my tree, okay, so I'm not actually checking something while I'm creating a new space. There's a couple of ways you can do it, you can check out a new branch like this, it'll tell you you know I'm just testing, or I can say make a new branch, call it test and then I can check in there, but what we do.
What we're going to do now is we're going to say "buy" and we're going to say "I'm just testing," so now we're in a branch called "testing," which is why it's so important to have a nice message, see how friendly? Is it really difficult to learn? If you can't visualize these things, let me come back here. I want to point out that Visual Studio Code has noticed that we are in testing. I did a bad job with my drawing right there. Well, Visual Studio code has realized that too, let me close this real quick. I made a mess, here we go, but we're in a world called testing and I can say git log and I could say it's cool, you know your brain. the header in testing and main are both the same so it doesn't really matter we are both looking at the same files so I can say you know this is all wrong all this is wrong new tests here test it is wrong and let's say that this is also wrong, I'm going to try something else here, so I made two major changes and you know, I'm even going to go as far as to say that I want to remove test two because it was a bad idea, so I'll say let's remove it or that we get our test M.
Oh, that's interesting, so it won't let me because I made changes. Well, I'm going to go ahead and say force this to happen. Sometimes you have to be very careful if you say: F ​​to really understand you're saying I mean it I know what I'm doing so it says are you sure you want to delete? that you made some changes. Maybe now I know what I'm doing. You better know what you're doing. doing, but I'll say yes, I'll pretend I know what I'm doing, okay, look, that's been removed, it's warning me that it's no longer here, so let's be aware of that, okay, now let's go over here and see how our changes get the state. in the world here in the parallel universe of testing, we have deleted one thing and changed one thing, so I will say cool, add a point, so I changed one thing and deleted one thing, confirm, this is something testing I think it is better , okay, so in this world we have a file called test test - it's gone.
I put my new test here, everything is wrong and now we can say git log and this is interesting, what is happening here, well, head. where we are now this universe the present time is testing there is another thing from before that is in main that is where all my coworkers are doing their work and then there is the first thing that I did so the time was like this and then I interrupted the time and i headed in this direction and created a new parallel universe called test, now other people could continue in this direction and i might want to merge with their universe i want to merge with their universe i want to go and say check out main now check out right look here a bunch of things are going to change what I pressed enter one two three okay remember in this world and we'll say git log to test it main is main I can't even see that test exists test two is back never died okay and I can see that expressed.
If I want to use other ways, I can go and look at tools like Visual Studio that allow you to do some of these things on your own where you can visualize the changes, but I like to go and see. those things here but you will notice if I do this I say git log this is a graphical way or another way to see those changes that you see on the right this log here this area is the same as this let's go back to the tests to demonstrate that git checkout testing enter okay so let's go here we're going to look at that log there's our history to see our history here we could say all the branches you can see main and testing and how they relate to each other so there are a lot of great tools that will allow you to see this, pick the one that makes you happy and helps you understand what's going on, but a lot of this is just time travel in different ways expressed, okay, cool, so let's go back and say git checkout main, here we go.
We are back here in this new world. We have test and test 2. We can close our get history here. There are no changes here. Now we talked about how Main was doing her work somewhere around the center. We come out here and branch out. We made a test branch while main continued, how do we bring this back to mainline? How do I take the work that she was doing during the tests? Okay, I want to merge that flag with the main line when I merged the branch. with master or in my case with main, okay, so what are we going to want to do here?
I'm here in Maine and have some changes elsewhere. I got my changes in testing, so I'll go and say git merge. the tests are fine, so I could go and do that, but I might want to make sure I'm clear about what's going to happen and whether or not there's going to be a problem, there could be a conflict and I can resolve those conflicts that we can talk about. those things or you can do what's called rebasing, which is a little more advanced and we might want to cover that in another future video. If you find this useful, let's say git merge and see what happens.
Okay, check this out, let's update. I'm going to fast forward the time, I see you made a couple of changes here and a couple of deletes here and three deletes there, that file ended up disappearing, okay, so look, now we're here in main, let's go and take a look at that and our registry has main and tests are the same, so we took our changes from our little workspace, our little area there, and did a bunch of things. The nice thing about this is that you can have a small branch get paid. you know, new feature, I want to go and create a new feature, see how we're doing on the new feature and I'm going to run these tests, this test here, I'm just going to be silly, okay, I'll make a bunch of copies. create a completely crazy world here with a bunch of new files, so I have like five files here, okay, and you'll see that for four new files and I'll say add, add, commit, that's a lot of work, okay? now I'm going to say "pay" main look at the right side look right above me right here one is gone.
I'm going to say "pay" new feature they are back you could have a lot of work they are changing branches It's a whole parallel universe with a mr. Spock has a beard and is just a mess, it's something else now that you're there in the parallel universe making changes as a test, let's say I said well this is good, not all bad, so I'm changing line one of the test. get add test get commit I got this right, now we're going back to the continent, to the world where it's still bad and I'll go, everything's fine, so two people are working on a new feature on that. parallel universe, the other one is on the same line in the same file, okay, add, oops, add, period, confirm, I think I got it, so in my world I think I have it, testing is another one if I check. to see the new feature which is another one my branches are starting to go a little crazy what's going on there's a lot going on here if I want to see that or visualize that I can do it remember by looking at all the branches see all the different things that's happening and you can See graphically in Visual Studio what's happening there, so it's interesting, but the important thing here is that two people have changed the same line in the same file, so there will be a conflict at some point.
Check the name. get new merge function conflict I couldn't merge this auto merge failed can you fix these conflicts and resolve it for me? Now there are tools that will do this job for you, but it's good to know that you could be using an uber. and that's how you get around town or on a bike, it's nice to know how a car works, it's nice to know how to drive a stick shift that you may never need, but it's a nice little thing, it's nice to know, so look what What did. here created a file, took my test text file and said well someone said this is good, someone else said this is good, you see how they put these little lefts like everything points to the left and then that's when everything points to the other address, which one is, okay or is everything okay, well what you could do is edit this, let's make sure we see what that file looks like because I want to show you there's no magic here, let's open it up I write it in notepad just to make it clear that what's literally in the file is a bunch of characters and I could fix it and I could say that's what's supposed to be correct and then I commit that this is how I fix my conflict, okay. one thing I could do, I'm not going to do that or in a tool like Visual Studio code, it's like I could, except the one that just came in the incoming new feature branch.
I could accept the current one. I had before and say I'm in charge. I could keep both and figure it out later or I could go and maybe log in and share my screen with someone else and go and figure this

stuff

out when I compare the changes. next to it I can see fine, one person said it's fine and another person said it's fine. I need to decide that, but I have to resolve this conflict. You can see it will appear as a conflict down here, this needs you. To solve it, then what are we going to do?
Well, let's accept the incoming change and say okay. I'm going to press save. I'll come back here and say get status. I don't say Okay, we brought these files in from a new feature, okay, there was no problem there, but we don't mark it as a resolution. We didn't say our conflict is resolved, so I'll go and say "get add." great, get the status, now we have a bunch of

stuff

, I'll say, get the commit, brought in the new work of the new feature, okay, and now I'm back in the main line, new features that are doing their thing . a parallel universe there, I haven't done it, it's not the main one, it's the main test that we did 10 minutes ago, that's also relaxing, we can go in again, visualize these things by looking at Visual Studio, okay, and then look at it like this.
Look at that look, this parallel universe came back together at the end, which is very, very nice and then I can continue with my work, but again, at any time, if I had to leave, I could come back and I could choose, I could say. well, you know, oh, I did a really good job, I just want evil Spock with his goatee to bring it into our universe or I just want that line, there are all kinds of more advanced fun things you can do, but the root problem is basically. That's interesting, I want you to understand that you can't lose your job if you pay attention, you can almost always go back in time, fear not, there are many great tools to help you commit.
You often notice how I often engaged with a lot of silly and silly messages. I can crush those compromises if I wanted to make a cool, well-written message. In this case, of course, it was always me, but if I had a team, we could also push and pull. from a central location like github, maybe I'll do that in the next video, so I hope this gives you an idea of ​​how I like to think about git and you find it useful. Everything was filmed on video without editing, but there. You will arrive in about 33 minutes. I hope it has been useful.
If it was, leave me a comment if it sucks. Go to another channel, but I hope you subscribe to this one. Thank you.

If you have any copyright issue, please Contact