93% of developers use git which actually feels to me a little bit low because 100% of the developers that I've worked with use git it's got a tighter grip on the Version Control industry than Google does on your personal data in this video the prime engine is going to walk you through not one but both of his git courses I'll try to keep this intro short because Prime does a better job of talking in front of the camera than I do but I just wanted to let you know what you're getting into now in each
course there are 11 chapters which means 22 chapters in total you'll learn how to set up git what repositories are get internals get configs branches how to merge how to rebase get reset what remotes are how to use GitHub with Git and ignoring files with G ignore in the second half of the course you'll learn how to Fork AO how to use ref log merge conflicts rebase conflicts squashing stashing reverting cherry-picking get bisect get work trees and tags it's a lot the first half of this course primes course number one is really all about learning
how to use git as a solo developer and course number two covers all the stuff you need to know to use git effectively in a team Prime has spent over eight months writing these courses and the rest of the boot de team and I have spent that same amount of time really helping to edit test and refine them so I hope you enjoy them but this is a very Interactive Ive course I do not recommend sitting down and binging it in one sitting there are interactive lessons and projects the entire way so get your hands
on the keyboard and actually follow along in fact I actually recommend that you take the course on boot Dev and go ahead of prime and then watch him go through that same lesson so you can see his approach his commentary and his Solutions after you've had a chance to experiment and and challenge yourself and do it yourself now all of the content in this YouTube video and all of the content on bootd are completely free there's no need to sign up for a boot Dev membership to get value out of this course that said all
of the interactive features on buev are paid features so if you want to be able to submit your own assignments if you want to view Solutions chat with the AI chatbot or get a certificate of completion at the end uh you will need a paid membership for that and you can actually use primagen code Prime YT that will not only help us at boot dev be able to produce more courses like this but that also supports the prime engine directly that code Prime YT will get you 25% off your first month or year if you
choose an annual plan of a boot dodev membership one last note if you get stuck and need help our Discord Community is literally just a few clicks away so join the Discord Community ask for help and let's talk about get all right we are now going to officially start the entire boot dodev learn get I'm going to go through my I'm going to go through the course that I created I want to do it and it's going to be awesome here we go we're going to go through the course we're not going to watch the
videos because guess what this is my course in 2005 after license disputes with bitkeeper lonus Tal's creator of Linux you may have heard of it sort of runs the web not a big deal decides to write his own Version Control he wrote git in 5 days and within a couple years it became a widely used Version Control and now today it is the de facto standard for all developers to be clear when I say get I don't mean an insult from across the pond and I don't mean GitHub gitlab stash or any of the others
all of those companies use git they are not git git allows you to track code changes over time by author with a set of commands to search manipulate and revert history in simple term git creates a commit a commit is just a set of changes tied to an author time of day and other information as many commits as you want can be added to the graph at any commit you can Branch off and create new commits on the new line any of these branches can be merged into any other Branch including the main line commits
can be squashed into one commit and commit messages can be edited also git commits can be reverted just in case they don't want terrible code git is very complicated piece of software but the interface and operations are very simple and in this course we're going to be going over installing and configuring get porcelain in plumbing commands inspecting G history branching merging and rebasing undoing changes and remote repos and GitHub I hope you enjoy this course and in about another month or two I will be releasing part two which will go over all the advanced features
Advanced Techniques with merges and rebases and conflicts and of course just really diving into some of the more complex parts of git but in this course you should be able to get everything you need to become quite proficient in the real world incl including understanding how git works the name is the gagen I already have everything done I might need to update boot dodev hold on one second all right there we go I'm going to get the latest version here we go go install I thought they I thought that was a thing H anyways okay
there we go we got the new boot dodev everything's looking good let's do a little boot Dev version oh yeah looking hot looking good perfect I believe I should all be logged in so I'm just going to go like this just to make sure that I'm logged in there we go echoing rebasing his base there we go everything good I believe I'm I believe I'm all good perfect okay submit so this is the cool part by the way so this tool was developed I think the motivation started with my course and other courses I think
Lane was developing one that also needed it as well but this tool is super cool so you copy this thing you paste it in and when you go right here look at that it says hey you did everything correct okay fantastic all right we've already installed git I already have everything installed I don't need to worry about any of that all right we'll do that thing as well okay perfect the CLI is so cool it is all right read the friendly manual one of the best parts of G is that all the documentation is fantastic
but that wasn't always the case by the way it was actually the the git documentation to this day I actually can't read the uh man G tag page still okay so everybody knows what a tag is right we all know what a tag is a let's see add a tag reference in ref tags unless DV dlv is given to delete list or verify tags um okay okay I think we understand this right unless f is given the named tag must not yet exist and then this is happened to create a take object or requires take
message unless M or f file is given and editor is started for the user okay what the hell is a tag though can you just tell me what it is otherwise a tag reference points directly to a given object I know it's just like is this just a wild I'm surprised the very first description isn't being like a tag is a mut a immutable named pointer I'm just like what the fu is this all right who created get obviously I did a by the way lonus tvols did create git in 5 days and The Story
Goes Like This he created git in five days because one of the one of the maintainers of Linux broke the bitkeeper license to Linux bitkeeper said you can use bitkeeper you're just not allowed to reverse engineer the protocol and somebody reverse engineered the protocol and get and bitkeeper said get the hell out of here get out and so they actually had no more uh subversion at that point or whatever bitkeeper was so he wrote to in 5 days now remember git was not friendly at all you had to use all the plumbing right you had
to use like you had to like cat out the file you had to create the tree like you had to do all the tracking yourself and it was not fun right it was not good it was not good but anyways lonus did it all in just a moment and he did it in five days then on the sixth day he rested porcelain and plumbing for whatever reason get is compared to the crapper uh rip John crap and so porcelains the outside the good stuff uh the plumbing is like the hard things the like the underlying
tools you can use with Git all right so in get commands are divided into highle commands and lowl commands the porcelain commands are the ones that you will use most often as a developer to interact with your code some porcelain commands are these on don't worry about what they do yet we'll cover them in detail soon absolutely by the way some examples of Plumbing are this one get apply give get commit Tre get hash object in which I barely know any of what those things do we'll focus on the highle commands because that's what you
use 99% of the time in fact I've never professionally use the lower level commands right BCT is I I I believe is a porcelain command um reflog porcelain command cherry pick porcelain command it's a bit confusing right all right 99% of the time porland commands are used to interact with Git yeah but you can and I have done it but it's really good to understand how they work if you understand how the the plumbing works the porcelain makes a lot of sense all right quick and fig we need the configure get uh with your information
uh whenever you code yeah blah BL blah blah blah so we got to do this thing we got to add our name in our config so if you've never done config and get get just has this whole Global it's literally just a file that's all it is is just a file and it's either in global space which means it's in your uh home directory or it's within yourg fer so kind of either or there anyways this is pretty good so we can uh we can do this config set username email so I'm going to make
sure let's see uh get config uh local what do I got here oh whoopsies uh is it List local I always forget how to use this one air keys does not contain get config what what what is it it's it's list oh yeah I forget list is the only one config is the only one that has this older way of doing a bunch of Dash dashes whereas like when you use something like get stash you go like get stash list whereas with config you go this kind of list and always it always I always have
to remember what the hell I'm doing right there okay local so as you can see I have all these things these are all the good stuff this is uh from graphite so don't don't mind that here we're going to probably want to do stuff little get config uh list GP name do I have a name in there I do I have the name uh there we go I have email perfect bada bing bada boom we got those things already set so I have all that and you add it to your Global so your you're Global
by the way if you just go like this you can go uh whoopsies get config right it's right there it just takes the latest value all right and so we also have this one finally let's set the default Branch we'll talk more about this so we're all on the same page we're going to set the default Branch to master to begin with so the funny part is is that um hey hey now let's see hey now Global and then you have to go uh what is it is it add look at that there we go
add there we go so it takes the latest one probably need to do an ad might want to make a little note there never caught that problem only level two week I had to reset my entire account all right make sure it works so there's a reason why we do this so we can show you to do it differently later right but it's Master by default true but a lot of people already have it say updated to main or to trunk or something else so I just wanted to make sure that we had this such
that everybody can change it um and see what it is so there you go all right so we can C the config awesome you saw that we CED the config everything looks good all right we're going to kind of rush through these early ones because I don't think they're very they're not that important and when you're learning how to use git these ones don't make a lot of sense like what the heck is this config thing why are we setting all these things we just got to do it to set up your repo so you
understand how git works right so this is all confusing stuff you're probably very confused if you're new to get that's fine it's [Music] okay all right so all right the very first step uh of any project is to create a repository a get repository or repo represents a single project you typically have one repository for each project you work on it would be wild to see many repositories for a single project unless if you're considering uh Forks SL yeah webflix you like that a repo is essentially just a directory that contains a project other directory
or files the only difference is that it also contains a hidden git directory this was a big eye opener for me is realizing that the that the dogit is literally the entire state of your G project it's like the entire thing and so if you're ever having questions about what's going on everything is actually stored in here so when you think oh how does it know every like how does it know all my branches it's literally in the git directory everything about it is in the git directory uh webflix this uh this course we'll be
managing content for webflix an imaginary self-hosted video streaming application can you imagine why would why would we name it webflix that makes no sense let's see navigate to somewhere in your file system where you'd like to store the project and once you're there create a new directory called webflix all right uh rmrf I bet you webflix already exists in my oh my gosh get the hell out of there oh get the hell out of there okay makeer webflix there we go and webflix there we go now I'm in here it's brand new right it's empty
nothing in here and so I'm I'm assuming we're going to have to get init get init just creates the new empty directory right it doesn't do anything other than it creates a brand new directory it uses our config let's go so I should be able to go ls- la you can see a git folder right here if I find inside the git folder it's pretty empty it just has all this stuff it has a bunch of sample preh hooks it has no objects which is where it stores everything it has uh nothing I believe even
the head is a little bit goofy if I'm not mistaken there you go that was weird cat get head there you go weird huh getting it yeah all right so anyways we do all this one awesome so now that we have our uh repo initialized let's actually get into the stuff is this VOD G stay online it's actually going to be moved to the uh boot dodev YouTube there we go we got all this this looks good let's go return to our browser done got him man I'm so good at this I'm getting so much
stats look at this I'm already level two a file can be one of the several States let's see a file can be in one of several States in a get repository here's a few important ones untracked staged committed okay this is very important this is also very important to understand because I've lost so much work not understanding the difference between all of these all right the get status command shows you the current state of your repo all right so assignment every good content management system needs a table of contents create a file in your rout
called contents. MD and add the following lines let's do this all right Vim contents. MD d uh paste this thing in Bam Bam get status you'll see right here untracked files that means git doesn't know anything about this this file an untracked file means that it's never been added to the index which is like your staging area or it's never been tracked so it just says we don't know what's in it so if you delete this file you lose every last bit of content because I'm pretty sure there's been a lot of people that have
goofed that up yeah I've done it it hurts it's emotionally a bruising experience to accidentally have a file that was untracked you think it's tracked you do something and you delete it and Fs you removed untracked files yeah removing untracked files is is emotionally painful because you can't really recover it it's a right of passage it's a right of passage to emotionally bruise yourself all right there we go so now I should be able to jump in here I should be able to run the little tool there we go everything's good all right so staging
staging you'll notice the term index a lot so if we go into here and we go mangit uh what's it called add you'll probably notice the word index quite a bit in here and the index is literally just the changes that you have staged onto your system that means any untracked files become tracked files and only the entire changes are tracked at that point there we go uh add this one let's see for example I use Arch by the way right without staging every file in the repository would be included in every commit but that's
often not what we want all right so you want to get add the file so I'm going to add the contents and then do this now me personally whenever I do stuff I usually hit a get status if the tree represents what I want it to be meaning that the changes are what I want and we have just this one untracked file I often will just use get add this now here's the deal about get ad okay that's a little goofy all right uh get status uh when you do this here I'm going to go
like this I'm going to go touch Fu if I go like this get status you'll notice that Foo is untracked as well if I make her uh Fufu and CD into Fufu and then get add this you'll notice that Fu remains untracked that's because get add dot adds everything at that directory and Beyond it doesn't add it doesn't add things in the directory P you have to use different ones like get add capital A that kind of stuff but we're not talking about that okay we're not talking about that uh there you go get get
the hell out of here there we go status we got that fantastic um so I should be able to just run this we've now added it our contents have been added we're looking good we're looking good oh man I'm getting so much experience points I I'm I'm almost level three after staging a file we can commit it a commit is a snapshot of the repository at any given time so this is very very important and this is a thing that a lot of people don't understand about git git is not storing diffs git stores the
entire history per commit so your entire git everything is in a single commit and that's very very important distinction to make because a lot of people don't realize that okay so our assignment is commit the contents to file this with the message add contents this you would normally start a commit message with a obviously this is because we're doing stuff with boot dodev so it wants to be able to keep track of all your commits and all that so there we go then run get status skin you should see that the file is no longer
staged right all right so let's go back here uh let's zoom in uh get commit let's see uh get commit there we go we did that and so if we go get status you can see we have a clean working tree get log one line You'll see that we have one thing right there let's see wait it so it doesn't store per change commit no and density I'll show you why in just a moment so this course is meant to really show you what is going on here all right so now that we have that
I should be able to just take this boot. Dev paste that in there go right here awesome I did it I'm I'm smat I'm smat I'm real smat uh half of git you've learned half of G you've literally learned half of git we just get commit status add commit right that's all you need to know status add commit that's like most of I know that's crazy to think of but that's it half of G easy you're like you're like a senior engineer at this point it's not near half though I know of course it's not
actually near half because when you go like this get uh uh when you go like this man get Dash you'll notice that there's 151 possibilities but of those possibilities three of them is what you pretty much use constantly which commands adds a file to the staging area Prime is it Prime no add right it's in the name dummies it's in the name name dummies all right get log get uh okay log is fantastic by the way log is one of those sleepers that people don't know how to use but there's so many good stuff to
a log get repo is a potentially very long list of commits where each commit represents a full state of the history a git log command shows a history uh in a repository this is what makes get a Version Control System you can see who made the commit when the commit was made and what was what was changed so there's a lot of cool things so here so this right here so they we'll see what uh he made us do this goes get no pager I believe this just simply will output the git log so normally
when you do git log it actually outputs this like second screen that's kind of like less if you've ever use the Tool uh less that's all it's doing instead no pager just prints it directly out it just prints it to standard out and log is the command N1 means the last 10 commits but what you really want to do is you want uh you can do things like one line that will make it nice and smooth so you can just see this nice beautiful thing you can do uh parents which will do annotation we don't
have any parents yet we don't got no parents we are the Batman of commits uh and you there's a bunch of stuff graph is really cool if you're working on something cuz graph is you'll notice that there's like a little Aster right here it will actually graph how your commits are being merged back in and how the uh different branches are going so we're orphans right now we're effectively orphans right now or you can think of us like Adam maybe we're the first huh it's not that bad right right all right do the one of
those there we go bada bing bada boom all right so let's get into some real stuff different hashes my latest commit uh or so in this example the commit hash was this our commit hash was what 78 blah blah and that's because whenever you do anything with Git the hashes can't you can technically do a hash collision by being able to generate the same git changes from the same author at the same time and whatever other information that it uses with the same parent and all that you could actually create the the hash is consistent
it's recreated every single time so it's an important Point all right there we go if you're not careful you'll have two commits with the same hash false you'd have to be very careful to create that and I don't believe that's even a uh it's not even like a yeah g is the original blockchain for those that are wondering all right you may have noticed that even though we you and I both have the same content in our repositories we have different hashes yes we already went through all this yes they do a sha one it's
beautiful which does let's see which does not affect the uh the hash of a commit the commit time stamp message author's preferred text editor even though it should I do think all Vim hashes should start with 777 a little bit of luckiness to it to me that's the only appropriate thing to do all right the plumbing so far we've used git in a porcelain manner but the let's see but to Sate our insatiable curiosity Sate is a weird word okay Lane may have done a little bit of writing for me in this one just so
you know uh let's take a look at the plumbing all right it's just files all the way down all the data in the git repository is stored directly in the hidden file you can actually see that look at this if I go like this if I go find inside the git folder you'll notice something right away look at this look at that thing that thing looks just like this thing right here right 7805 172 7805 172 look at that huh kind of crazy right that's my commit okay sneaky git very Shakespearean I know he's very
Shakespearean he uses phrases like upstairs and downstairs and it's crazy all right git is made up of objects that are stored in the git objects directory uh a commit is just a type of an object correct use log 10 to view your commit hash do this inside the object directory and we already did that we already saw it which uh let's see which matches the format of the file you'll notice here too so this is something that you probably don't know about Linux uh this right here this is called an inode busting effectively what IOD
busting is is that a directory can actually end up having too many files in it if you ever done it weird stuff starts happening happen happening so instead get to prevent iode busting or to prevent iode whatever it is you'll do this so this takes the first two letters and then does this right i' I've ran out of iodes before yes I i' I've goofed up myself so a directory can only be such a large size so therefore this just helps separate out things this is very common you'll see this in CDN cdns do the
exact same thing the actual naming underneath will start doing weird stuff like this screw you unlinks your list yeah it is it I've done it once I dude I note issues are insane by the way they're crazy yep I ran into this with a massive log directories exactly you have to do I note busting or else you just life is painful and I did it once and then once you do it once you never do it you just never do it again all right that's it that's all there is to it all right so that's
why they do this they take the first two and they turn it into a directory so that way it just kind of spread things out all right so let's take a uh let's take a look at what's inside this suspicious get commit object file have you ever tried catting one of those things the first thing I ever did when I found out get was just a folder is went right to objects went right to my commit and tried to cat it out and it's just this right that's a bunch of right there okay what the
hell does this even mean all right so you can't really do anything no it's a mess uh let's see the contents have been compressed to Raw bites so that's why git remains small is because git compresses things and that's very very important all right now the lesson let's see okay hold on this lessons run and submit are a bit different because you need to tell boot. Dev CLI where your commit object is located all right so we're going to do the exact same thing so I have to do this but I have to give it
this name right path to file right so I'm going to grab this thing and I'm going to go like this uh let's go get objects 7805 05 this thing and then submit I believe I did that correctly this one I screwed up last time I tried to do this let's see failed to get this thing page not found wait who's he what's he all right let me reread this one sorry sometimes sometimes I'm not good at reading lessons Okay I just want you to know that rtfm read the friendly manual sometimes I don't read the
friendly lesson okay let's look at this again try to C the contents of the file we already did that nope it's a mess the contents has been compressed um we can we can print in a decimal I don't really care this lessons run and submit are a bit different because you need to tell boot. CLI where your commit object is located uh run and submit the test but provide the path to your commit object file as a second argument run lesson lesson ID okay so let's try this again because I'm apparently I'm too stupid so
I need to go boot. run lesson ID path to file okay get objects 78 052 there we go look at that I'm getting so much exp I'm level four you guys wouldn't understand practically a grand wizard Arc Mage I don't think you're supposed to be a grand wizard right that's not uh you don't want to be that you don't want to be that guy okay I forget sometimes I forget things okay uh luckily git has a built-in Plumbing command cat file that allows us to see the contents of a commit without needing to fuss around
with the object files directly so you just use get cat file- P cuz technically like if you're viewing a tree you have to use a tree command you know there's all these different things but cat file just allows us to look at everything at once without having to worry about its type and all that uh so you can just go get CAT file this so if I do this get cat file this guy and do 78517 I believe you only need up I think you only need technically you only need four to specify it you'll
notice something when I cat out my commit you'll see the author and all this and then you'll see the message that's so it's nice then you see this tree command look at this tree this hash we don't know what this hash is right so I can actually go get uh get cat file- P 5B 21d and then you'll notice that it has a blob object and that blob object is a Content so to kind of put this in perspective you can think of a tree as a directory and you can think of a blob as
a file so that's kind of important to know so when I cat file this thing you'll notice that it's contents which is the exact contents of our contents file they're identical so do you see what happened there why did I capitalize B for those that don't know why I capitalize B uh when I type I have dvorac but even more so when I type numbers 1 2 3 4 5 6 7 8 9 10 you'll notice that I typed out symbols symmetric symbols it's because I've optimized my keyboard to prevent wrist pain from happening because
I program a lot so I have to hit shift to type my numbers right so sometimes I'll do a capital B when trying to type stuff because I'm still holding shift does that make sense okay there's no there's no reason or Rhyme or anything to do with it it automatically lowercased it for me it didn't mean anything all right so there you go you can see that so this is actually really cool what just happened here look at this I was able to cat my commit out take the root directory tree cat that out see
the file that was there then cat that file out and see the contents of that file this is very important because we'll use it later to grab stuff out it's kind of fun it's kind of it's kind of neat so there we go so we can do that all right so use cat to do all this one pass an argument to the CLI notice that boot. Dev CLI test for this lesson take an additional argument to noted by this one right there we go you need to provide the hash okay so I need to provide
the hash there we go all right we'll do that we're going to grab that bad boy and I'm going to go like um I'm going to go like that and then I need to grab the is it which hash are we doing that you need to provide the hash of your last commit okay we need to provide the hash of the last commit there we go so I'm going to go back up here I think that's all I need to technically do d s and then take out this little slash I think that should do
everything I need to do there we go got it first try got it so good at this why would you ever need to do that in get you'll see you don't technically need to do this in get but it's really good to understand why this is where the big eye opening moments about to happen for everybody about how git actually works because what we've seen so far is that we've made one commit right we've made one commit and we're going to call it a and in that commit we have a tree that's like our root
directory and inside that tree we have a blob which happens to be some big long hash and it is contents. MD all right this is very important so this is our Commit This is commit a so now we're going to add this and we're going to see how this changes all right all right I believe I did all this all right trees and blobs now that we understand some of our plumbing equipment let's get into the pipes here's the terms you need to know tree is a way of storing a directory blob is a way
of sorting storing a file so you can see right here I already showed you this there's the tree we are able to go through through the tree and get all the way to the blob right assignment use get cat file again but this time use it on tree you should see a blob with its own hash use cat file again on this one submit the sees with The Blob hash okay we should already be able to do all this uh because we actually already did this all right let's find this little bad boy right here
where are you where are you where the hell are you there it is hey there we go by bing bada boom able to grab all that stuff out I just grabbed out the file hash cuz I knew what it was or the blob hash all right second uh second command uh reminder of commands get log um and Cat file that's what we've been doing log is a porcelain command where cat file is a plumbing command you'll use log more often when working with the code uh on coding projects but cat file is useful for understanding
gets internals we already kind of talked about that so we're going to create a second file called titles this is where things get really interesting are you ready for this uh all right so we're going to go like this titles. MD paste this all in here delete that one uh run through and then we need to save stage and commit the file with the files long as it starts with a B right that's the thing get uh add this get commit with a B There we go awesome and then run the CLI there we go
I'm going to grab the CLI and we're going to do this bada bing bada boom all right so we've created a second commit right this is how you will understand get get stores an entire snapshot of files on a per commit level this was a surprise to me I always assumed each commit Only Stores the changes made in that commit now type one in the chat if that's what you thought too I assume a lot of you thought the exact same thing that get stored Deltas right yeah I mean look at this a lot a
lot of changes in here and I think that's completely normal anyone that doesn't think that get stored Deltas right away you're lying to yourself you're like yeah I didn't think that I always knew that it didn't do that no you didn't okay your your small brain did not think that we all thought that because that's totally normal thing to think okay well it's true that g stores entire snapshots it does have some performance optimization so that your git directory doesn't be get too unbearably large get compresses and packs files to store them more efficiently get
D duplicates files that are the same across commits now you're probably thinking isn't that just Delta stores hold on let's find out let's just find out okay watch this we're going to use git cat file and we're going to find the hash blob of our titles MD okay watch this all right so I'm going to go like this uh I'm going to go uh let's see I'm going to go get log log one line I'm going to grab this last that's my last hash right there we go I'm going to go get uh get cat
F I know there's better ways to find your your current hash just shut up this is good enough this is good for people to understand now notice that we have our tree also notice we have our parent now so our parent is our previous commit so we can actually walk back up the tree if we needed to this is if you're wondering how git log works is that it stores parent pointers as part of the commit all right anyways so we're going to take our tree and go get CAT file - P this now notice
that there's two blobs okay there's two blobs here the first blob is the previous contents and this one is now titles okay so I can actually take this and go get CAT uh file- p and I can actually cat out the titles file uh I can actually go to this one and get cat uh G cat uh cat file- p and I can cut out this one and this will give you the contents of that file but notice this right here I want you to look at this would you look at it for a second
I'm going to jump into my parent get cat I'm sure I explain this in a moment in the course but I like to explain it this way uh there's our parent commit I'm going to grab that tree notice that that tree is different than uh is a little bit different like everything's a little bit different this is the older version of the tree get cat file- P this look at contents look at contents it stores a unique tree per commit but that that doesn't mean it stores the entire file it just stores a pointer to
the file so when I say A commit stores the entire history it stores every reference I know kind of mind blown right that's why it's efficient because what happens is you can think of it this way is that let's say we have Commit a and commit a has the parent tree and then it has the blob that's pointed to our contents file okay and this is like let's just say it's like e f and then a bunch of letters right blah blah blah blah commit B adds that new file and so it's going to have
that same tree but this is going to be a different notice that the hash is different on this tree because this tree has a new set of kids so something has happened to this tree which means that it can even point to trees that have not changed that's very important so we have a new tree we're just going to call this one one we'll call this one two and this one is still pointing to that exact same EF blah blah blah blah but then we have a new one which is going to be our titles
which is going to have its uh we're going to probably need to call this like titles and then it's going to have its own commit right here and so it doesn't update this this Remains the Same so it's very important to understand that all right so let's see what we have to do here all right we're going to use cat file we're going to view the uh the hash of The Blob for our titles and you can do that save that hash somewhere in your notes all right let's save this hash somewhere in the notes
because we have to find it there we go it's right there I can just come back to that later add a new new directory to your project called quotes inside add two files all right so let's uh Vim uh what is it you say quotes they say quotes I can't remember quotes yeah I think so uh what was the first one called uh star wars. MD and then what was the other one uh Dune MD Dune by the way is a great movie Dune Dune can also be fall under the good Sci-Fi um all right
so there we go we have those two things stage and commit both files in a single commit with the message C add quotes perfect okay we can do that uh get status you can see it's right there get add this thing get commit DM put all that in there get log one line should have three commits you can even go like this get log - P which will show the differences so this first one adds this new file uh from nothing to quotes Dune from nothing to quotes Star Wars and then it doesn't make any
other uh edits right and there's the previous commit which adds titles and the previous commit before that which add contents okay cool awesome we got all those things all right so we did all that one use the command CAD file to view the hash of The Blob for uh titles again you'll notice that it's still the same hash correct there you go because the file hasn't changed run submit this thing Perfect Isn't that cool Isn't that cool I think that's pretty cool I mean I think that's very very cool for me that was a very
mind-blowing moment is to understand how git works because then it no longer felt as confusing and that was my big kind of like I I I I got really really confused for quite some time when I first played around with Git because of that thing all right what does it mean that files uh which were once committed then deleted will be forever kept by git so technically it's not forever kept by git it's forever kept by your history unless if you prune your history so you can actually prune your history out of git and so
that way it would actually clean up any broken references so it doesn't actually keep say deleted commits that don't exist so get prune DF yeah so that will go through so we will actually do that I'll I believe in this uh in this section we will actually revive a file that was long lost or a commit that was long lost it's kind of obvious that it's store snapshot otherwise you need to walk back the tree a lot for files that don't change often yeah I mean it's it's obvious in hindsight but I think the first
time you think and you download the first time you ever use a a Version Control you think wow how could it possibly ever store everything it must have to like create the repo by walking all these links that's why it gets so fast is it doesn't it keeps your tree and then when you need to change your directory it literally just walks that tree and recreates every single file at each one of those points right that's but the first time you you wouldn't understand that right let's see 100% of the working let's see 100% of
working with Git is checkout Branch ad commit push Force push rebase or merge yes exactly that's why I say that's well I mean it's not 100% it's like 99 95 there's log there's ref log ref log is incredibly important we're going to go over that there's also like get checkout so get checkout theirs versus ours it's very important when you want to be able to just grab an entire change from one side of a merge [Music] conflict let's take a command apart get config okay so here we go we're going to actually start talking about
config now cu the config is actually useful to use and understand because sometimes you actually want want to be able to change ways in which your G experience changes or in which in which it operates so let's look at this all right so let's take a look at the command so get config is obviously the top level it's still the older style command so instead of get config ad it's get config D- ad which is kind of a pain in the ass Global is where to store it so it's either Global or local there's some
other places you can store and get but nobody actually stores things in git right uh or in those ones at least as far as I can tell I don't know of any use case where you store in system uh I'm sure there is a use case I've just never personally ran into it I've always just used you know local or Global all right uh so Global stored in uh this right here in your uh home directory get config whereas local is stored inside your git configure right so if I go like this if I go
in here and I go uh let's see uh let's see what is it LS or find in my git folder what is it name is it config I think it's config there you go yeah there we go uh cat config it'll say here's the things that are inside of your local repository so when it creates a config object it actually takes your globals then it takes your logos and kind of combines them one at a time all right assignment you can actually store uh any old data in your git configuration granted only certain keys are
used by git but you can store whatever you want yeah it's just a key value mapping that's all it is so you can like uh I know when I was at Netflix we actually had a lot of information stored for how we operated over certain stuff so it just I used to have a bunch of Netflix stuff on my system at one point uh set the following useless key/value pairs in your local git configuration so right here so we're going to do this for our locals all right so it's not too hard so you can
go like this get config add local so I want to add a key value and I want to do it locally and then what do we want webflix uh CEO okay the prime gen okay uh actually yeah we'll call the prime gen and then we'll do uh the CTO as the lanen right that's the actual CEO of um what's it called of boot. Dev and then valuation valuation mid it's a mid it's a good mid valuation hey who here wouldn't want a good mid valuation git has a command to view the contents right so if
you just go List local it's going to list everything you can also just cat it out right so as we did earlier you'll see here's our top level uh section here's our keys and values uh so a good thing to notice here is that this is a SE section and this is a key so when you look at this you'll notice that this is the section this is the key that's important to know because you can actually delete all configuration by section or by section Keys all right so there you go you can List local
so if I just go get config List local it'll just uh list all my just local only files right here all right so let's grab this thing jump in here paste it in your company position mid isn't that everybody's company position by the way configs were one of the more confusing parts for me not confusing by how they operate because they're actually exceptionally simple but when I first started using git config was something that I executed once and then I never looked at again and then then whenever I had to touch it I was just
like I don't want to do this right and then I just got all confused by stuff and then I just it felt confusing because I refused to just spend the three minutes it took to understand said it and forget it exactly and then you just don't know how certain things operate and simply because you didn't learn this really simple thing this is why I did config because config is one of those extremely useless things you should pretty much never need to know but that one little moment you need to know it it's very useful it's
very very useful we've used list to see all the configuration values but get flag is uh useful for when you're trying to get a single value right so we can do get uh key remember a key is a section. key name so username webflix CEO there we go so I can we can get the web value so I can go uh get get uh let's see what is it web webflix webflix valuation and it'll go and get mid nice right doesn't get config username just get it uh get config user.name yeah it also gets it
you could get must get is the default operation but it's good to know that because you can also do do set right all right there you go beautiful we did that one uh bada bing bada boom all right this is looking good all right the unset flag is used to remove a configuration value for example get onset key let's remove the CTO all right so we go like this uh get config unset right everybody you know everybody loves a good unset right I really hate the term unset uh which one are we doing CTO CTO
yeah all right I just fired Lane because you know what screw Lane what happened when you tried to unset uh oh try using unset to remove the section I forgot to do that one if you do this what ends up happening key does not contain a section right so you need both a section and a you need both a section and a value or a key name for this thing to be able to be removable when you use unset you have to do unset section if I'm not mistaken I always forget the entire section it
failed because you have to use key and value right you have to use both you got to use both duplicates typically a key Value Store like python dictionary you aren't allowed to have duplicate Keys strangely enough git does not care yes if you look at my git config uh Global uh list Global and then we GP what is it um uh a nit you'll notice that I have in here three of them okay I had in it default Branch master in it default Branch Main in it default Branch Master yeah it just takes the last
one my bad my bad on that one yes you can yes but but if you do that you have to force push right Force pushing is the only way for you to be able to change history for everybody else and if you do that you will ruin the whole repo and everybody will know all right duplicates unset all so unset all is if you want to unset uh entire thing you only need a section then right or sorry unset alls if you want to delete a multi- existing uh key value combo which is kind of
odd having an key set combo it's just kind of weird so if I do this and I go like this and I add a bunch of CEOs I should be able to go in there and go get uh config List local and now you'll notice we have a whole bunch of CEOs right we have four of them me plus uh Carson Warren and Sarah all right so if I want to undo that I can remove all CEOs by doing unset all right get config unset uh web flick flick flick do CEO there we go CEO
has multiple values unset all bada bing bada boom get List local all the CEOs are gone anyways okay so now that we did all this pretty straightforward right pretty straightforward stuff there we go there we go awesome we're kind of getting through these things uh you know the config SE section it's it's it could be boring but whatever it's fun uh you know it's you got you just got to learn these things right all right so there you go so we're going to do the the next thing um which is we to remove an entire
section now webflix is a section we have so if we just go remove section we can actually remove all of it so if I go back here and I go um I can add all of this and go get config uh if I go get config List local you'll see that I have a bunch of webflix stuff so if I go get uh config what is it it's remove section right it's not unset section you know how many times I struggle with remove section versus unset and all of that man whenever I've had to do
anything like that I've screwed it all up it's so easy there you go make sure I really get it out there you know what I'm talking about we want to get it out there and then also you'll notice that if I go like this cat config uh uh cat get config you'll notice that it actually removes the section right just fun little fact fun little fact if you're wondering you know what I mean bless you my goodness yeah thank you yeah you just edit the file directory I personally find that uh I would just rather
jump in here and edit this often than doing all that other crap to be real it's just it's just much easier CU this other thing is just it's just really hard you know it's just really really annoying all right locations uh there's really only two locations that you should really be concerned about I actually never used a work tree specific location or a system location I've really only done Global and local I find location location Lo anyways in my experience 99% of the time you'll be using Global to set things like your username and email
the other 9% of the time you'll be using local to set Project Specific configuration the last 1% of the time you might need to fuss around with system in work tree configuration but it's extremely rare yeah I've never I've never personally had to do it I just know that it's been done on my system so there you go here's the set of uh here's the set of what's it called ordering so if you have a work tree specific it's be the most specific therefore that's going to be the one that gets presented then local then
Global then system system is like the it's kind of like just think about it like uh JavaScript and merging arrays right system is for all users correct global global is not Global it's not a global list if that makes sense it's a local Global you know what I mean it's not a global global it's a local Global all right suppose you set username to Prime at the system level username Lane at the global level and username TJ at the local level which value will actually get TJ even though TJ does stream but he sucks okay
just so you know yeah Global's the user it really should be it it really should be repo user system for me that seems much easier to understand and TJ catching Strays TJ's always catching Strays okay shots fed all right let's see which is stored at the home directory that'd be [Music] Global all right so what is a branch so now we're going to get on to branching so a get Branch allows you to keep track of different changes separately for example let's say you have a big web project and you want to experiment with changing
the color scheme instead of changing the entire project directly as right now on our Master Branch you can create a new branch called color scheme and work on that branch and when you're done if you like the changes you can merge color scheme back into the master branch and keep the changes if you don't like the changes you can simply delete color scheme branch and go back to master so underneath the hood this is what's actually happening look at this beautiful little little graphic do you like that graphic it's beautiful huh it's beautiful does this
make sense so here's a big thing that you need to understand tips just the tips the tips is the commit that is the latest one on whatever Branch you're looking at okay so you need to know your tips and then eventually they should merge back at some point because that's how branches work they should be branched off of some uh some they call it the merge base this would be called the merge base we don't have that as part of this graphic so this is called the merge base or the Le or the uh most
common ancestor is one right here and so this is for when you merge it finds this thing right here and then merges things together merge tips use rebates yeah exactly so just so you know these are all commits branches lit like a branch a branch is literally a pointer to a commit that's it orphaned branches are wild yeah I don't even know how to create like honestly I don't even really know how to create an orphan Branch it's exceptionally difficult to create an orphaned Branch uh it's just not something you do you know on purpose
all right so let's see because a branch is just a pointer to a commit they are lightweight and cheap this is why when people say branches are really cheap it's because it's just a pointer that's it uh which branch you're currently running get Branch there we go so I can go like this get branch and you can see I'm currently on Master fantastic remember you should be on Master because we set initial default Branch to master at the start of this course yeah yeah yeah so there we go um fantastic and we're going to do
that and we're going to execute this thing Bada Bing Bada Boom Confetti feeling good confetti out of my mind all right default Branch we've been using GS default Master Branch interesting interestingly GitHub a website where you can remotely store G projects recently changed default Branch to master to main as a general rule I recommend using Maine as your default Branch to work uh if you work primarily with GitHub yeah because if you don't you have to like go in to every single it's just a pain in the ass right that's all it is if you
don't do that you have to actually go into your projects and you have to set it as your whatever other Branch you're using as the default or else it will use main as the default and then you will get cloned down a repo and then main will be like this empty branch and then you have to undo all of it there you go gitlab has main too and I think newer versions of git has main as default too I'm not sure if G newer versions of git has that as default um like if I go
like this uh get let's see get config remove section um oh don't do that unset all um let's see what is it it is a nit uh default a branch there we go and so if I go get config list there we go you'll notice that I still have this one did I not do this correct am I oh is it lower B oh is it really lower B is it really lower B Branch nah that can't be right right why why are you still here why por and Maria why are you still here oh
it's cuz I'm not doing gosh I'm so stupid Global globalist there we go I've have undid my Global list this is very important to undo your Global list there we go list there you go it's gone you can see that it's gone so if I go back here and go like this make dir testy uh testies and CD into testies uh we'll go in here and we'll go like this get an it get an IT using Master the name of this initial Branch this is theault Branch name subject to change to configure the initial Branch
name do this right here initial Branch name uh names commonly chosen uh instead of master or main trunk Development I've seen Dev I like using trunk just to mess with people okay I think it's funny here get might be old uh get oh it could be old I'm on uh 245 it's pretty new get uh latest uh version 246 yeah I'm only back I'm only I'm only off by a little bit I used using trunk just to feel something exactly exactly there you go okay so now that we're here there we go all right so
here we go all right how to rename a branch so you go go get Branch uh M for rename right classic M for rename am I right am I right old name new name all right we're going to set our initial Branch to Main and then we're going to rename our Branch all right here we go uh let's just weo back in here and get Branch M Master main get uh config add Global s uh we can actually even do it that by the way you can also do it at a local level so I
can go uh nit default default Branch uh what the hell the thing called it's called main so there we go so I can actually do this at a local level so now only this repo has the default Branch as main whereas all my other ones will still have whatever my Global version is it's very good to know how to use locals and globals it can be very useful I've had to do a lot of things where I have to goof around with different versions all right there we go wasn't a lowercase B I think the
lowercase b was an accident I want to say it was an accident anyways there we go I'm going to copy this one oh my gosh uh okay dang it so it's gonna my thing requires me to be a globalist I'm now a globalist I am now officially a globalist globalism all right really just Alex jonesing on this thing all right there we go visualizing branches uh throughout the rest of this course we'll be visualizing branches by the way this is how git does it as well so if you do not know if you go uh
man get commit I believe they have it in commit no uh rebase yeah you'll notice that they effectively do this so I TR I tried to copy a effective version so that way it's easy to understand easy to see okay sounds good yeah yeah yeah yeah all right let's see this means a branch called main with three commits a c is the most recent commit as you can see A to B to C Branch there you go so this one right here means a it splits off from a and there's d and e on something
called other branch and B and C on Main so they are diverging branches with the merge base of a all right everyone get that I'm going to be using that term a lot merge base uh answer the questions based on the following diagram which commits are part of Lane's Branch uh none because he's a CEO and doesn't work these days but it's going to be GH this one bam got it man I'm so good I'm globalist all right there we go all right throughout the rest of this course oh I already answered this one which
are part of commits of main uh it's going to be a b c d got it first try all right VIs izing branches oh we're doing it again dang we're going to do primes Branch huh primes branch is EFA or a EF EFA man I didn't even get close you should already be on the main branch uh your default branch and you can always check with get Branch I wonder if there's a way to name your default Branch something that would break your system can you do rmrf uh see two ways to create a branch
right get Branch New Branch name this creates a branch called New Branch uh the thing is I rarely use this uh command yeah I rarely use this command reason being is that whenever I create a branch I also want to switch to that Branch right right so I typically use get checkout B just because that I mean I'm I I guess I am a boomer it's hard for me to break that habit but the newer ones is get switch C so I'm trying to show you kids you youngans to use get switch C all right
that's the one you want to do all right I'm just so used to get checkout B I can't help it so if I use get checkout B sorry I'm old my fossils are creaking you get the idea okay so what this does by the way whenever you create a branch it takes your current location and that's where it points to all right so when I do this my new branch that will actually create a new loc it'll create it'll have the exact same sha or the exact same uh commit yeah it's your head location so
it's it's good to know that because a lot of that's kind of like one of those confusing jumps people have to make oh yeah on itchy there you go all right anyway here we go uh create and switch one called ad classic so let's just do that right now there we go I've created ad Classics uh let's see and then let's see run get Branch to verify so I can go get branch and you can see that I'm on ad Classics get that and if I go get log you'll see that I have ab and
c and if I go get log uh main you'll see a b and c the same thing they're the same thing I believe if I even go like this uh find uh get what is it uh grep refs something like that right you can actually see this right here so you can see it right here so if I go right here and I go uh cat that you'll see it's pointed to this thing and if I cat uh main it's poed to the same thing there you go makes life easy for you to know these
things learning gets sucked yeah learning get well it doesn't it's just it's just time cons it's a bunch of little things that you just have to learn all right switching branches uh we talked about using get switch to change branches there's another command you'll certainly run into and it's been around for a long time and older developers use it get checkout okay calling us older developers hurts a little bit me in the past me in the past get switch is a newer command that is meant to be more intuitive and user friendly uh it probably
is more user friendly because get checkout is kind of like this grab bag because you can also like check out sides of a merge conflict there's a lot of weird stuff shows the history get okay get developers of a certain generation and that's me also uh it's recommended to use get switch over get checkout for simply switching branches that's what they say let's okay let's switch to a branch called Prime all right there we go uh the new way the old way right there you go for this course we'll stick with get switch right there
we go all right switch to Branch main run get branch make sure we're on there switch back to Classics run this one run this okay I'm not going to do that yo dog uh I'm happy for you or congratulations or I'm sorry there we go we passed I'm not going to switch around but you get the idea it's just get switched without the- C for create that's all all right upleveling our abilities will uh use the ad Classics Branch to add a commit to the project without affecting the main branch so we're going to actually
create the D here in other words ad Classics Branch will have all the commits from Main plus a new one all right so we're going to switch to add Classics we're going to create a new file called Classics CSV and there we go so I'm going to go uh Vim classics. CSV uh go here I'm going to yank that bad boy paste it in here of course the classics uh you know The Princess Bride I actually watch this every Christmas it's literally the greatest movie of all time here we go all right so we have
this we're going to stage and commit the file the commit message to start with D all right run commit okay here we go so we're going to do that one get add this get commit Dash D is great there we go and you should be able to see the commits with the branch with get log we don't need to do that let's copy that bad boy paste it in make it happen B bam bam bam got it we're all in the good stuff so let's go over here so we're about ready to start get into
some good stuff log flags as you know get log uh shows the history of your uh commits in your repo there are a few Flags you'd like to know short full no I like to I don't really use decorate decorate typically works well uh if you want to see where things are coming from so you can do get log uh decorate full if you want to see a bunch stuff on Line's the one I use a lot okay this is the one I always use because if I go get log you get like all this
crap but if I go get log on line you get that that just feels nicer right that's the one I want what the hell is decorate well this is decorated right now and the reason why it's decorated if I'm not mistaken if I go uh no pager no pager uh no okay there we go all right it's not doing it effectively decorate it decorates default default version I thought I thought there's a way what's the way hold on let me go like this on line uh T out there you go so there you go that
that took it off so if you pipe it to another program this is kind like a non-decorated one a decorated one right here shows where you're pointing at so head which is also pointing to add Classics main is on C that's what decorate does so get log decorate equals no will not tell you anything about where stuff is at does that make sense and then you can also use git log remember how I talked about graph graph is pretty cool graph uh one line so you can kind of see that I'm just going it's just
all one line right now there's no there's no change right now but we'll get to the point where we start seeing some changes don't worry we'll see it we'll see it uh there we go fantastic I think that's all I need to do run get log with full decoration we already did all that explain the decorations let's go we got it we got the confetti we're confetti out of our mind I'm level seven by the way you guys won't even understand what it's like get propaganda hour absolutely uh Kung Fu no get Fu remember git
stores all the information in files in the git subdirectory at the roof Ro of your project even information about branches the heads or tips of the branches are stored in get rep's heads if you c one of the files in that directory it should be able to see the commit that the hashes points to which we already did use find and Cat to find the commit hash of your main branch we already did that one uh what is stored in get ref's head uh one file each for a commit oh what is in there I
forget let's see it is going to be get ref's heads is going to be each one of the branch names one file for each branch containing the commit hash of that Branch points that one let's go let's go I'm a genius nope we're not going to watch this branching and get is practically free and it really is kind of the core operation when using git but at some point you have to get that work from a branch back into the main line and this is where merging comes into play now a typical workflow for pretty
much every Dev looks like this first we need to update our repository to the latest code this is typically done through get fetch or get we'll cover those more later you Branch off the main branch and give it a name that kind of represents what you're working on new feature a you fix the bug create the feature update the docks and create your one or more commits on that Branch then finally you merge those changes back from your branch into the main line typically when you're at a company this will involve some sort of poll
request on GitHub on stash on gitlab but conceptually it's no different than executing git merge on the command line oh what's the point of having multiple branches you might ask they're most often used to safely make changes without affecting your or your team's primary Branch however once you're happy with your changes you'll want to merge them back into your main branch so that they make their way into the final product all right so here's the visual look at this beautiful thing and then notice this this right here is called a merge commit it's very important
to understand merge commits because if you don't you don't understand why rebase is good so merge commit and especially when you look at a log we'll look at the log here shortly but it will actually show you why uh or how these things kind of exist and why they're unique and why it allows for log graph to be very nice uh so hold on let's see what the assignment is just to make sure I don't get ahead of myself uh first switch back to main next our contents file is eerily empty yep update uh update
it to contain this all right there we go now the yep and then we'll this okay perfect perfect let's go all right so what we're going to do is I'm going to go like this we're going to get check out main oh wait no wait get get switch add Classics get switch main don't use checkout we don't use checkout we're not using check it out we're not doing it all right and then update this file right here don't you do it uh get status it's nice it's not it's not mgit all right there we go
so commit uh let's see commit the changes with a message starting with e all right so let's commit these changes get add this get commit uh e uh let's see uh contents such contents with a new line at the end why I don't know why there we go so now we have this one we have ABC uh abc e abc e and ABCD awesome so we should be able to do the whole get log graph all look at this nice bad boy look at that look at how graph does that it's nicer in one it's
it's nicer in one line honestly one line you can see right here so there's ad Classics it's been branched off at that point and here's this guy so it's a nice way to look at all your stuff there you go why not use checkout it's just older switch is the one right all right there we go fantastic right so I should be able to just do that everything should be good there we go confetti it out of my mind all right merge commence we are merging two branches together with diverging history look at this thing
right here the diverging history simply means that main branch the one we branched off of at Point a has commits and we some branch have added more commits main has B andc our Branch some branch has DNA that means when we merge we need to be able to create a new commit that represents these two diverging histories as one this is called a merge commit and it's the only commit with two parents the process for a merge commit looks like this first we need to find the merge base the merge base also called the best
common ancestor is the nearest ancestor that is in common to both branches and in this case that would be a we then play main Branch's commits into a new commit and then we play some Branch into that same commit when all the changes are in that new commit we commit it to Main and in this case we call it f and we give it two parents one parent pointing to C from the main branch and the other parent pointing to E from some Branch if you use G log you will actually be able to see
the diverging from a the two diverging commits and then the coming back together in F merge commands are the result of just merging two things together yeah so what a merge commit does or how a merge works is that when you merge in something it takes it finds the most common ancestor or the merge base then it merges Main and this one together to make one Super One make one super commit adds that to the front of the branch that you're on and then has two parents which is where you came from does that make
sense so if we were to merge Vim Chads only in main while using this we would find the merge base or the best common ancestor uh in this case a replays those two commits bam creates a special commit called a merge commit and then this thing has two parents there you go fantastic right uh so in our current webflix history we have this we have main abc e and we have ad Classics which is D so when we merge we should have this like we should have an F commit that's going to be this little
merge Branch right here so let's just do that now get merge ad Classics I assume that's what we're supposed to do and we wanted to go f so that way we can denote it there we go we're going to write that and we just did it perfect right so now if I do this whole on line decorate graph parents business hell yeah that's a lot of stuff you can see right here classics branched and then came back together and you can see right here that this is a merged base because it has two parents or
not a merged base sorry uh why would I say merch base it's not a it's a merge commit because it has two parents never worked with two parents children yeah most children in get do not have two parents this one does so there you go this you can actually watch it because this one points to this Commit This one points to that commit they both point to the same merge base there you go now that everybody knows feels good right a lot of arch users out there confused about merge commits all right so logging has
to be one of the best tools in the git belt because git has extensive logging and observability if you need to recover work visually understand how you got to this point commits along the way messages that you have created where the branches and tags are including in your repository your remote repository and of course all the tags that you currently have and much more than logging has it let's break down a Quick Command right here get log on line graph decorate parents now this looks like a lot of options but actually it'll make a lot
of sense once you understand what those options mean one line will give you a condensed view of your history first off the hashes are shortened to seven characters which is the minimum amount get requires for you to specify hash also you get the commit message this gives you a nice quick view so you can can see what happened in the past graph will draw all the little lines so you can see exactly how your commits have diverged and come back together through merges decorate will give you the branch and tag information this can be nice
to see how far you've straighted away from a branch or where a previous Branch might be parents will give you the parent commit upon every other commit this can be very nice for merge commits because you can see where the two parents came from to create the merge commit go ahead give it a try yourself oh we already did this I already kind of explained this beautiful niceness right here uh each Aster represents uh a commit in the repository we actually already talked about all this this is fantastic why does the first uh line show
three commit hashes uh because it's the first commit in the history no because it's a merge commit with three parent commits no because it's a merge commit it shows its own hash and the hash of both of its parents we already talked about that I think that makes sense right wait where did where did my log go oh I didn't print out the log there you go you can see these are the commits right here these are the lines this is its sha and then its parent Sha see that's parent parent parent parent it's commit
Shaw parent that's its commit Shaw this is its parent it's the parent or the shaw it's parent the shaw this is Batman right here no parents beautiful asky beautiful asky there we go all right merge logs let's see you can output your get log decorate graph parents aside from the hashes look something like this we already taled well we already did this we just got to answer new questions why is the weird diagram EG all these things uh whoopsies I I didn't mean to click that it's what happens to your brain on Arch Linux after
10 years that's not what I wanted to do um it demonstrates the branching structure three commits were merged into the main no it demonstrates adding Classics was merged into main boom that's what it demonstrates it's beautiful I want to make sure you guys get it all right a fast forward merge does everybody who knows what a fast forward merge is I'm curious type zero if you don't know what it is I'm actually curious about this well lot of zeros dang dang that's a lot of zeros a bit I'm shook I'm shooking right now okay the
simplest type of uh merge is a fast forward merge let's say we start with this one main branch and then delete vs code now we run this on Main get merge delete vs code because delete vs code has all the commits that Maine has get automatically fast forward merges in other words the best way the branch you are merging onto if the tip of that branch is the merge base then you can fast forward merge does that make sense yes in other words I tried to one more time I tried to that's why I've been
trying to say the word merge base remember a merge base so for these two commits right here a mer the merge base is this right here so in this example this one uh this one was main this one was add Classics so the merge base was this right here so if Classics was branched off instead of such contents the merge base is the tip of the branch you are merging on therefore you there's no Branch right it can just literally update the pointer the end kind of sounds like rebasing main no it doesn't sound like
rebasing main that's not what rebasing does we'll explain what rebasing does in a moment rebasing has nothing to do with merge people sometimes goof that up a little bit it's not what it does um all right because delete vs code has all the commits main has get automatically does a fast forward merge it just moves the pointer of the Basse Branch to the tip of the feature Branch that's all it does bada bing bada boom all right uh we'll get to mer we'll get to rebase here shortly so you're just adjusting head pointers that's pretty
much what you're doing so when you're doing a a fast forward merge you just main just now points up one right assignment uh because ad Classics branch has been merged into main we don't need anymore delete that Branch okay we'll delete it uh create a new Branch off of Main update titles uh let's see add a commit to that branch that updates titles MD file and add Curious Case of Benjamin Button as the final entry in the list and then use G okay we got to do a couple things here hold on hold on let's
delete get a check not checkout switch de see I I always mess that one update uh titles titels uh there we go uh let's just open this up and go add classic contents what we doing titles uh Curious case for Benjamin Button is that the one we're doing titles MD we're going to add The Curious Case of Benjamin Button there we go we've added it so now we have that and then we're going to just create a commit with G all right get add this get commit dasg a curious case all right there we go
uh run one line to see what we've done here get log one line you can see right here here is update titles here's main Main's one behind you'll notice that this would be the merge base right so Main is currently if I were to merge this onto main main would also be the merge base and that's very very important to know all right so let's go in here let's do one of these there we go does all this updating bada bing bada boom looking good looking good confetti let's go all right so fast forward so
now what we're going to do is we have this diagram and now all we need to do is just merge it back on so we're going to switch to Main and we're going to merge update titles onto it and you'll see what happens here so get check out main sorry I did check out not switch get log uh you'll see that I don't have G on here if I go on line it's probably easier to see no G if I go all you'll see that g does exist only in update titles there we go and
then we can go like this graph and you'll see right here that g is on the end so it's just straight ahead so now if I just simply merge get merge uh update titles you'll notice that it does a fastforward merge and now notice if I go like this get log one line notice that this one had a branching Factor this one does not there's no Branch there's no merge commit uh and you can see by me going like this get um uh parents so you'll notice that this one is a merge commit because it's
merging e44 and 7 a0 this one is not because it's just having its parent to be one behind very important to know okay that's a very important thing to know people just you know they just don't know these things all right there we go I hopefully I did everything correct and I didn't accidentally go forward sometimes I go forward too fast and screw everything up all right so now we're going to go to rebase everybody thinks rebase is the most awful thing ever and it's on Twitter if I go to Twitter I guarantee you I
search up the word get rebase and there's going to be something awful up at the top get rebase or hopefully it's going to be me saying people don't understand it all right mer all right here we go there you go look at that see open Slack someone help with rebase branch in Flames sends thoughts and prayers close the slack go to gym rebase Force push I up I get rebase like look at this it's just it's an endless supply Hacker News is having a get rebase discourse again I like this Comon a lot see it
uh blot the blah blah blah blah blah blah blah blah blah blah again they hate this one I think this is the way okay personal opinion rebase is tight rebase is the only way to do it something about get rebase thanks yall for coming I don't even get this one okay I don't even get this one this one must be get rebase this is get rebase so you got to be careful when you're rebasing okay you could screw up the world I just want you to know that okay you could screw up the world rebase
might just be one of the most misunderstood features of git where the fear typically kind of comes from is that somebody changes the history of a public branch and when I say public Branch I mean a lot of people rely on this Branch for their repos as well and of course when they pull and the changes have been somehow altered in the past all these conflicts and these weird git errors start happening and it just causes a disaster for everybody and then everyone says rebase is terrible I will never use that only use merge well
skill issues you used it wrong to understand rebase you simply need to understand its primary use case rebase helps you to take the diverging commits from one branch and move them to the tip of the base branch that the feature branch is based on now that sounds like a mouthful but it's actually pretty simple so take this graph right here we have two branches Main and Feature Feature branches from Main at commit a and Main gets B and C added to it while the feature branch has d and e now we want to be able
to take the feature branch and get those changes from Main now with your current knowledge you would probably merge main into feature creating a merge commit and that does have consequences and we'll discuss more about that in part two but for now let's focus on rebase rebase is is going to allow you to move forward feature Branch from diverging at Point a up to diverging off of Point C allowing for a fast forward merge if you wish to get it back into Maine this also allows you to maintain a merge commit free history and again
there are some consequences for that and they can be quite nice and that is it you'll notice this gives you the opportunity to do a fastforward merge and kind of have a free of merge commit history this will allow for some Advanced G features to be more easily usable if you maintain this type of workflow okay so rebase is very very simple all rebase does is update where your branch points to this is well okay I mean technically there's actually a couple different use cases for rebase but let's just start here this is the first
one so pretend we had Main and we had feature Branch if we were to get rebase main on our feature Branch it would take the pointer which is which it's parent pointer it's its merge uh base is pointing at a and it's going to go all the way to C then replay your commits d and e and now you have a linear history which means you can do a fastforward merge okay so it's actually really really simple and you'll notice that DNE even though the commit message is the same you will now get new commit
Shaws why would you get a new commit Shaw well that's because D its parent is no longer a it's C so therefore D has a new sha e has a new sha because D has a new sha now you have to fix all the conflicts if there was a conflict while rebasing there would be a conflict while merging if you're if you're experiencing continual conflicts it's because you don't know what you're doing and I will explain why in a little bit okay okay buddy can you calm down again whenever I see some whenever I see
somebody say something about all these conflicts and all this stuff with uh with rebase what it makes me realize is you don't know what rebase does and how to and how to get around stuff so it just moves the merge base exactly it just moves the merge base and that's really important do you talk about conflicts and G two yes so git one is all about using git for yourself get two is all about using it for a team so it takes the code from d and e and applies them to uh code version C
yes so literally so the exact operations of get mer rebase does this so let's say we're on feature branch and we say get rebase uh main what happens is that we check out main I'll call that the target Branch we check out Target Branch we then take Source branch and apply its commits to the tip of Target Branch then we update Source Branch to point to the new uh to the new tip why is it uh important to change basis uh reverting so people really hate get revert it does make things better when you need
need to revert so reverts typically happen in larger companies if you're just working with like two or three people you're probably never going to revert anything and that's fine but if you have say a 100 people working on the same repo and there is a test that needs to go out that day and you accidentally screw up Main and you need to unscrew up Main and they can't wait for you to go okay this is going to take me a couple days to fix you have to revert your commit out of the history and then
you have to re-release into production the reason that's nice if you properly do what I consider the best way to use git which is to always rebase right so here's ABC you always rebase such that you can do Fast Forward merges and whenever you do this you uh you take this and you merge it into a singular commit right you squash it is what's that called is that if you run into a situation where you need to use revert or revert I always I never know how to I never know how to say the word
revert in that kind of tense uh or in that kind of sense I always call it revert I never I don't know what to do here anyways when you do this it then is really easy to remove this right always rebase in local branch I rebase in public okay that's crazy don't rebase in public you can also fast forward merge too yeah just do it with idea that's not a good way to do things I'm just throwing it out there knowing how git works and setting it up so that it can be very easy to
change things but uh but but sometimes I just commit a just a lot of commits you should you should commit early and often okay this is a good way to do things committing early and often is great do that but do you lose commit history when squashing it depends you loose your history of your local changes and that's okay you can do that you can squash them down to a single one so that way when you merge back into the main branch the public Branch it's just one commit now maybe you want those in two
commits if you want them in two commits then squash the commits into the two ones that you want maybe you want them in all the commits then keep them all right you can kind of choose what you want to do cuz when you revert you can do the same thing as you do in cherry pick and provide a list of Shaws to like take out or put back in uh get rebase interactive is the best thing that is get rebase interactive is very very nice and we'll do that for when we're squashing right why would
you go with interactive rebase and squash your commits into a single one instead of uh merging with a squash uh I do that that's how I do it so locally whenever I'm about to do anything I get all my commits prepared I rebase I squash and I push things up try making yes we can do this too uh this is one good way to do things but we're going to get to that that's later on right I'm not trying to we're trying to stay on task here okay lot of questions rebase is always a lot
of questions because rebase gets the biggest bad RP from the internet and most people have absolutely no gosh dang idea what rebase does and so then they're like oh but rebase is bad because it'll screw up your history and you're like you're right you can you can f yourself up with rebase absolutely you can chop off your finger with a skill saw it doesn't mean skill saws are bad it just means you should probably know how to use a skill saw before you just start slanging that blade all around right I know that's crazy both
rebase and merge can be used to integrate changes from one branch into another in some sense yes very very true anyways all right rebase versus merge BL blah blah blah we're going to do this one uh blank can add additional uh commit and blank does not rebase merge can add an additional commit rebase does not correct so if I'm rebasing and there's never conflicts can I still lose history for months go so I'm not sure what you mean by losing history people say that cuz they don't know what it means what are you attempting to
say if you have history that's in a public Branch you will not change it unless if you interactively squash rebase and then Force push which if you do that you're a bad person you should be fired that's crazy don't ever do that you will you will actually ruin everybody's life you actually will yes conflicts happen whether if there's a conflict while rebasing there's a conflict while merging that's a good good thing to understand nobody wants to see million see see your millions of commits just squash it yeah a lot of people prefer the squash all
right we need a new Branch uh feature branch and to be able to practice our rebase we want to not include some of the commits in recent main uh we're going to use get switch command and create and switch to a new local branch called update Dune but Branch off the decommit you can supply a commit hash directly and get switch so we're going to do this right here we're going to get switch Branch it off of Dune okay people so we're going to go like this get log uh on line and there we go
so D is that bad boy right here get uh switch dasc update Dune and from that one there we go I said update done you get the idea so if I do that another little oneliner right here we're going to see this beautiful part right here if we do on line all you'll see that head is pointed right here update Dune I'm close enough it's not my fault I didn't copy pasta what can you do okay so now that you see that this is good this is good good good good good stuff there we go
we're going to paste that in we should be wait what oh update okay it's actually requiring me to do that get Branch M up uh update uh done to update Dune I don't know why you got to be like that get boot Dev okay you can't let a man have oopsy daisies here so you never push until your feature is done or you need the force push yeah I I don't I don't I don't push my features up regularly I keep them and I commit them and I get everything I want and then I push
it up and then there's some there is some there is some a little bit of style points here of how you want to handle things after that some people don't like to make changes uh some people don't like to make changes in the sense of having to force push again so all PR changes will become their own um commits and then squash that one more time and then merge it when it's ready that's one way or you can merge your PR changes back into a single commit and and then you have to force push it
so it's kind of like you got to Riz get your own way and some people prefer the you know the the pr changes to be their own separate commits some people don't that's the rizing part you know also if you have really shitty cicd pipelines you may find yourself constantly you know doing that and get Force push every five minutes with amending draft commit yeah that's me called using get we've all seen that we've all seen it where it's just a wall of test test test test test test test test test test test test test
test test it's just the worst yeah I get a bad feeling when not pushing for several days okay I I mean that's fine you can have of either no one's telling you not to it happens it is kind of weird right I feel bad not pulling I like to pull pretty regularly all right so now we're going to rebase main this will do the following check out main remember I called that Target Branch replay one commit at a time from J diesel onto Main update J diesel Branch support to the latest commit the rebase does
not affect Maine while J diesel has all of its uh had all the changes from Main there you go so it's going to pull in those changes so our assignment let's add two commits to Dune Branch add the following quotes to Dune the spice must flow and then for that will be H and this mind killer all right let's do this okay Dune is a really good movie okay I don't care what you guys say all right wait spice must flow okay good uh get status so you can see that get add this get add
this get commit Dash I think it's h uh spice me daddy why not uh go into here that was H we're going to do I grab that one go back in here do that save that add get commit fear me Daddy I think so I think that's right I think we just got it okay so I should be able to get log and see this thing so there we go you can see that right here in fact I can go like this graph would make it nicer so you can see right now that I've branched
off of D you can see my little Branch off of d right here that goes up and does uh does this right here H and I there it is right so you can see the branch right here this is the main line This is the uh the new line that we're doing what is dash all it it lists every last Branch right so if you to list every last Branch you can I believe you can also forgive me if I get this wrong I believe I can also go Main and update Dune right you can
also specify which branches you would like to see how they do what is happening with that here let's take a look at that so you'll notice right here if you remember this right here was when we did our merge B our our merging and all that fun stuff right so this has update titles and Main pointing right here do I need to I don't think I deleted update titles did I did I forget to delete update titles get Branch delete update titles are you sure you want to delete it Force get the hell out of
here all right all right there we go so you can kind of watch this thing move right so there there was remember we had a split at one point right here that had DNE so this is the merge commit from DNE so if I go here I forgot to do parents this will make it more clear so you can see right here this is the merge commit for from uh which one is that one from E and D that's the one we created earlier this right here is our current One update Dune so you can
kind of see each one of the lines forming and we split off uh we split off on D right here so the split went up this way to H and I so it goes i h d CBA a for update Dune and for main line is going to be GF e D or is that or actually it's going to be gfd e CBA I believe that's how that that's the ordering there you go that's that's how you read it you read it from top to bottom left to right classic real real classic right there all
right Perfect all right we're going to do those two things we have those ones we're going to run one line I like mine where I did run line main you can see here's a more graphical depiction of it all right you can see that so now our goal here is to rebase it and so we're going to have uh does it tell us to rebase it I can't tell finally while still on that we want to rebase or change it so when we rebase them you'll notice right now here let's go back to this thing
you'll notice that we Branch off of D for I and H so when I go like this get rebase Main and reexecute this you'll notice it got a lot more simple we are now right here it's now branched off of G which makes it into a nice linear history all right we just moved our Branch forward you'll also notice oh I I didn't I didn't save the output or else you'd see that the the stuff all changed there you go pretty straightforward right there you go no conflicts why would there be a conflict we edited
different files so remember conflicts will happen universally since we do not have a conflict in a merge we're not going to have it in the rebase pretty much either uh there might be some Edge case where that's not true but I can't think of why that would ever be true because a conflict in its core happens because git has three operations add delete modify and so if two operations modify the same line it can't do it it doesn't know how to merge those two things because git operates on a line by line basis it does
not operate within code because once you operate within code it has to understand the intent of code and therefore it can't so therefore it's going to say hey since I can't understand the intent of code you've modified the same line you need to do something about it I don't know how to do something about this does that make sense all right the advantage of merge is that it preserves the true history of the project this is true you know where all the branches happened and where all the merge commits happened it it shows when branches
were merged and where one disadvantage that it can create a lot of merge commits which can make history harder to read and understand which can also make it harder to manipulate history with uh reverts and reverts can be a strategy especially in bigger companies I had the revert at Netflix probably 10 times in my life right it's real I've had to do it comments can cause conflicts I've don't know about oh comments as in comments and code yes comments and code yes a linear history is generally easier to read understand and work with some teams
enforce the usage of one uh of one or the other on their main branch but generally speaking you'll be able to do whatever you want with your own branches it's true how painful was it not painful at all uh when it came to that because I always did I always did the same stuff I never merge committed I always did all my stuff really nice and made sure I had a single commit so whenever I had to revert which did happen uh all I did was just revert commit revert commit walked away right easy easy
peasy right warning you should never rebase a public Branch like Maine if you do this you will destroy your life and what I mean by that is when someone pulls it will say your histories are out of sync and then you'll have this huge conflict problem and then you have to effectively undo everything uh it's generally good maners to rebase a public Branch onto your own personal branch all right hold on rebase a public Branch onto your personal Branch that's kind of a confusing question I think what it's saying is rebase a public branch and
change its history if that's the case no that's bad there you go rebase and get merge are different tools all right we already talked about this it's generally okay to merge changes into your own uh private Branch or to rebase your branch on top of a public Branch yes this is [Music] correct all right undoing changes one of the major benefits of git is the ability to undo changes there are a lot of different ways to do this but first we'll start by going back a commit history without uh without discarding changes all right we
have a little story you guys ready for a little bit of a story I don't even merge I just pull damn it's crazy why would you do that let's see okay the new internet webflix tried to add his favorite movie to the titles file but overwrite the entire file by mistake to simulate that on update Dune Branch go ahead and overwrite titles with just one line The Internship oh Vince Von oh Vince vaugh all right I don't know why that happened I think that's what they're looking for oh he actually doesn't even want that he
want the entire file overed there we go that's what that means if you're wondering this just means redirect output but it redirects output and destroys the file double carot redirects output and appends to the files all right make sure the file is changed by running get status and then commit with-j all right uh get add this get commit J interns am I right there we go fantastic am I right am I right am I right all right get reset is a command that can be used to undo the last commits or any changes in the
index by the way I use reset quite a bit okay not just soft either also hard but soft actually soft reset is an amazing thing to use and it becomes exceptionally good when you screw up a revert cherry pick or a rebase and so it becomes really good the get reset soft I know some of you some of you prefer hard but hard isn't always good okay it's not it's you can't go hard all the time you got to go soft sometimes trust me on this one I'll show you all right get reset command can
be used to undo the last commits or any changes into the uh to the index staged but not committed changes and the work tree unstaged and not committed changes so we can do re get reset commit hash or it it really shouldn't be commit hash here this is kind of a oopsy daisies it should be committes commit is a term used by get to say something that looks like a commit so it's some sort of hash or something that can be calculated into a hash right uh the D- soft option is useful if you want
to go back a previous commit but keep all of your changes committed changes will be uncommitted and staged while uncommitted changes will remain un are staged or unstaged as before so our current branch is right here it should be a commit J now we should be able to go to commit I um by doing a soft reset so I can go like this uh get reset soft now normally it's said to go uh in here and go get log one line and go and grab I and do this right here and go and get reset
I you don't have to do that you can also go if it's directly in history you can go get reset soft and go head which is where I'm pointing to and then the amount of steps you want to go back so I want to go head one back so that's going to be to I there we go we did a reset soft that if I go like this get status you'll see that I have the titles get diff uh staged you'll see that I've deleted everything for internship uh get diff you can see there's no
changes uh no uncommitted changes to the work tree and if I go get log one line-1 you'll see that I am currently on I pretty cool right so I just did I undid those changes while maintaining the changes available if you don't see why this is useful in rebase I'll show you later okay don't worry we'll show you we'll show you yeah it's good huh I like it I mean I personally like that there we go uh J should be gone for the commit log there we go we should run this thing yes uh yeah
git log uh G log uh get oh my goodness I showed this earlier git log p on line is is really nice too uh on line-1 cuz it'll show you the previous changes so you can see fear's the mind killer that was definitely I you can see that right there I'm more of a mixed kind of guy okay okay interesting interesting I can't really argue that can you just keep oh dang I was hoping I could get more I was hoping I could get more uh get add- P do you use this no I never
do I never do patch stuff I never do any of that interactive adding honestly it's that so this right here I would definitely use with an editor it's way way nicer um I've never used I've never used uh that no I've never used that yeah if you're going to do patch adding so uh get or um uh man get add uh dasp right this is interactively choose Hun's the patch so hunk I don't know how they determine the size of a hunk uh but hunks uh is just like somewhat of a change so long as
there's enough lines between two changes it goes uh here you go here's hunk one here's hunk two and therefore you can actually say I want to add this one but remove that one but if we do it with interactive it actually makes it a lot easier here I'll do it really quickly okay I'm going to do it really quickly okay there we go uh let's just there we go that's good enough uh let's bring it right up into the middle I'm going to just go in here we're going to go in here I I know
I'm screwing things up who cares uh's let's just go like this remove me right there we go I'm going to remove me so now when I go in here I can actually go like this I'm going to add one up to the top and one to the bottom and when I go in here you'll notice that there's two hunks those are hunks right there so if I were to go uh get add uh that- P you'll notice it's like hey do you want to Stage this particular hunk no I'd much rather personally go in here
and go like this and so I can go I want to Stage that one and I want to remove this one now I only have one change it's much easier to use a graphical editor for that stuff split is useful split is useful yeah so anyways all right let me just undo that one uh and then go in here and go get reset uh soft so now here's a problem here's a problem everybody I goofed up right now I have this commit that isn't quite right and all that I bet we could find the other
commit couldn't we oh we could but we're not going to we're not going to uh get status there we go get diff uh stage there you go you can see all the stuff I've added to it that's fine all right so get uh hard will undo everything so get hard will not only undo the changes and move your branch back it will also clear out your index and your working tree assignment get run status to confirm this one uh run get reset hard to undo the changes don't move on before you've done this okay there
we go so I can go like this get reset hard uh cat titles this now you'll notice everything's good there we go so I did a reset hard which will change which will undo the index and the working tree so like changes that are unstaged so that is not no because un well unstage yes it does unstage so it just depends so watch this so if I go like this uh let's go like this I'm gonna add a line right get status this is an unstaged change to the working tree get reset hard get status
it's gone very important but so if I uh get back here but if I CLI this Foo and I say Foo get status this is an untracked change very very important so when I get reset hard get status you'll notice that the untracked change because it hasn't added my working tree yet this is an unknown file it does not get reset hard important to understand that okay important to understand those things there we go we did all that let's grab that let's paste that in untrack get so fun with get ignore it can be very
annoying with get ignore yes uh there we go danger I want to stress how dangerous this commit or this command can be if you were to simply delete a committed file it would be trivially easy to recover because of the uh it is tracked in get however if you use get reset hard to undo committing that file it would uh it would be deleted for good yes you can delete by accident forever so if you have a change that you never committed you have an unstaged change hanging out and you do a get reset hard
you can lose all of it very important to be careful about that so be careful about doing that okay be careful reset to a specific commit if you want to reset back to a specific commit you can use get reset hard command to provide that and you have to provide a hash this will reset your working uh directory and index to the state of that commit and all changes made after that are lost okay so this is this isn't technically true uh I don't this must have escaped my eyeballs but they're not technically lost forever
you can still recover them via uh ref log or by looking at uh you can you can peruse through a lot of the G stuff and you can cherry pick back in this is true but it can be a bit of a pain in the ass to do that right again be super careful in part two of the course we'll cover more advanced stuff uh ref log has saved me many times it should ref log is very very good get reset hard blank undoes the commit changes delete uh deleting the changes forever unfortunately that is
not sure I'm not sure how that escape me it perceiving deletes them forever it removes the changes from your branch and moves your branch head so it appears that they never existed you can still get them right anyways I want to stress oh let's see hold on when provided a hash get reset hard blank moves your current Branch back to an older commit and destructively discards uncommitted changes correct there you [Music] go all right get remote uh often our FR ofies read co-workers make code changes that we need to begrudgingly accept into our pristine bug
free repos this is where distrib uh distributed in the distributed Version Control System comes from we can have remotes which are just external repos which mostly the same get repo history as our local one all right that's the nice part it's a distributed Version Control System right you get you get the idea uh when it comes to git the CLI tool there really isn't a central repo GitHub is just someone else's repo only by convention and convenience have we as developers started to use GitHub as a source of Truth for our code so GitHub is
just is just another version of your repo and that's very important connection to make because if you don't you might find yourself fairly confused by a lot of stuff let's create a second repo called webflix local and let's see as a sibling directory to our original webflix so we'll do a little CD blah blah blah blah so I'm going to go make derb back webflix uh webflix local there we go all right let's see run and submit the CI test from inside this one oh we need to get AIT to create a new empty repo
all right uh let's go like this let's CD back back webflix local get AIT jump in here jump over here paste that in all right we're moving we're moving fast adding a remote and get another repos called a remote the standard convention is that when you're treating the remote as the authoritative source of Truth such as GitHub you would name it origin there's also some like basic rules around origin that can be applied there's some convenience defaults and all that by authoritative source of Truth we mean that it's one uh one you and your team
treat as the true repo it's the one that contains the most up-to-date version of the accepted code some people call it Upstream Upstream can be kind of unique uh if you do your repo so this depends on your uh working order some people will have Upstream in a different fashion um so then origin if you're working in a bigger team you'll often find that origin is your fork of the of the remote and Upstream is the authoritative one Upstream there you go does that make sense it's good to kind of know this and you you'll
see this often uh origin is typically the one you uh work with and so if you're on a small teamworking by yourself you don't need to do this this would be kind of stupid you just need this uh you don't need to create a bunch of process for no reason but you do want Upstream when there is a lot of people working that's when it makes sense Upstream is usually when you're working from a fork in common F yes yes uh There He Go is that on top of branching yes a remote is a repository
right so so we're going to do that right here so here's the Syntax for adding a remote and it can be a URI remember a UR URI is very very important to know that so what we're going to do is we're going to go like this get remote add origin back up webflix remember a remote is just another repo there's nothing that says says it can't be local okay it's good to know that cuz sometimes people think remotes are only available like on GitHub it's not true it's not true it's not true anyways oopsies I
ACD went back all right let's go forward there we go let's copy this one all right so let's copy this thing there we go we have our remote POS uh properly set so we can fetch adding a remote to our get repo does not mean we automatically have all the content so if I go like this get log you'll know there's nothing here nothing ain't there fetch brings in all the changes this is very important so if I go fetch it's going to bring in all the changes this is fantastic right so if I go
like this get log not look what happened look what happened look at it would you look at it nothing's happened right well the reason why nothing has happened is because we didn't actually update our stuff and that's important it didn't update our branches yet this is good to know this is very very good to know and so we can also go in our get objects and we can find things so I can go like this get uh I can go uh find get uh let's just find and get you'll see that up here you'll see
a lot of these things right in here and you'll be able to recognize some of these there should be a 78 right a 78 in here there you go there's our first one right there that's our first commit that's commit a if I'm not mistaken 7805 uh get cat cat file- p785 look at that look at that a how nice is that huh get fetch money it's like it's like it's for free okay so there you go so you can see that we have all of our commits they're just not integrated yet so that's important
it's important to understand that that happens there we go fantastic so now we actually need to uh you know we need to do something about it now bringing the remote uh into this we need to run get fetch oh I apparently I did that apparently I uh apparently this one is it didn't actually check to see if I did a fetch first easy I ran ahead I ran ahead I ran a little too fast okay I ran a little too fast all right to demonstrate this run get log which we already did we actually already
did all that I'm sorry I ran so fast all right I can't help it so look at this beautiful thing we can actually do this right here you can actually log a remote Branch versus uh versus the origin like we can actually you can see the differences between them as long as we've fetched and did all that so pretty pretty exciting time so I can go uh so if I go get log doesn't work get log main nothing really in there if I go origin main you'll see all these fantastic absolutely beautiful uh oh did
I actually screw up our uh I think I might have screwed up our stuff no I didn't all right let's go let's go I'm a genius I'm an actual genius all right all right merge we can merge branches with a single uh local repo so we can actually merge in the remote Branch yeah yeah exciting what music is playing the music that is playing is going to be bits and something what is it bits and hits which is this is Skyrim but Loi you are a genius I'm not sure about that okay uh can you
explain the difference between branches and Upstream Origins origin or remotes so the second part of your question are called remotes remotes oh this guy's being really annoying here hold on there you go you're banned forever from YouTube I don't know how to undo it so if I don't click this button it's done it's forever uh dang it just it literally just left sucks to suck all right uh these are called origins or not Origins these are called remotes now remotes are just repos branches well they're branches they're just they're just pointers to to uh commit
within a repo and so there's a big difference there so an a repo can contain many branches and they don't have to be the same set of branches branches are just pointers to commits does that make sense so again a remote would be or a repo is just a collection of commits a branch is just a pointer to a commit it's a mutable pointer to a commit a tag is a non-mutable pointer to a bit uh a commit it took me a couple times to get that right GitHub is just one large gate repo that's
all it really is it really is just one large gate repo they do a lot of really crazy things so all right so now let's merge this stuff in so I'm going to go like this get merge uh origin uh main so I'm going to merge the main origin into my origin right here uh so if I go get log now you'll see all the beautiful stuff this Curious Case of Benjamin Button everything's looking real real nice fantastic so I'm going to go like that I'm going to grab that we're going to grab this bad
boy in confetti time [Music] yes there is no so this idea of local and remote it's it's remember git is a distributed Version Control one repo is not somehow the authoritative source and another repo the downstream Source every every repo is its own repo running and you're sinking between them so you can actually have many authoritative repos it's just typically to make life super easy you have one which is GitHub and then you pull and push that so everybody can pull and push to the same thing does that make sense there we go all right
GitHub blah blah blah blah so remember GitHub is not git is not GitHub GitHub is a product by Microsoft git is a source control GitHub is a way for Microsoft to make money and to scrape your data and to collect it all for the AI in which it's attempting to create Junior Engineers that cost less but still cost a lot and then to uh and then to use that to get companies to pay them yeah okay now that we understand what github's purpose is which is to steal your data that's why they give you free
free repos now let's look at this all right AI alert yeah create a GitHub account we already did this one assignment all right run all checks ensure that your GitHub user exists and is authenticated there we go I already have it I already have it authenticated and all that fun stuff so there we go all right get up repo just like we created webflix local repo and use webflix as a remote GitHub makes it easy to create remotes that are hosted on their site all right perfect we can create a new repo so hold on
before we do that I got to go like this GitHub the primin web flick I believe it should be there or did I name it something else I didn't name it anything so what I'm going to do here settings let me go all the way down to the Bippity bottom delete this suppository I want to delete it uh I have read the instructions uh the primagen SL webflix there we go delete this one holy cow I'm going to need to do I'm going to need to give a stool sample after this to really get everything
done whoopsy daisies wrong thing there we go do that thing all right assignment so I may have to darken my screen for this because I don't know if I have to type and stuff create a new repository on GitHub called this okay let's do that right now uh go on here actually I can just go right here create new repository let's call it a web Flix there we go select owner the prim engine there we go create go here we have a new remote right there fantastic looking good oh no we have too many tabs
open all right authenticate your uh local G configuration with your GitHub account I recommend installing the GitHub CLI with one quick installation I already have that uh GH authoriz authorization and then do that one let's see which one are we doing that in let's see add a remote in your webflix repo there rep points that one okay so that's webflix get remote add origin for webflix which is right here there we go be sure to place your username and do get LS remote to make sure it's all done correctly get a uh LS remote there
we go I just have that bad boy right there do I need to push up my changes I don't think I need to push up my changes it doesn't seem like I have to push up my changes but we'll find out yay I don't have to push up my changes all right so there we go get push origin main all this does is pushes up your branches changes to the remotes right so I can actually so with webflix local I can actually push into webflix and so therefore from webflix I can push into the remote
um so here just to just to show you that I go like this get Branch uh get switch uh we'll call it Foo and go get push origin Fu there there we go so if I go back to this guy I can go get branch and you'll notice fu is now there Fu was just pushed up from one remote into the next that's all we're doing is I'm pushing it to a repo and you can put permissions and all that on what can be done and blah blah blah blah blah that's what that's uh that's
what it does so there you go the GitHub is not like that crazy complicated in that sense it's just git the crazy part about GitHub is all the managing and making it scale and all that other stuff uh get Branch uh defu there we go all right all right what do we got to do here do I got to push up all my stuff yeah yeah yeah yeah yeah yeah yeah get push origin main there we go I push my main throw that in there run all checks confetti out of my mind there we go
have we gotten to rebasing yet we went past the basic rebasing yeah yeah yeah yeah yeah let's see pull H fetching is nice but most of the time we actually want the file changes yeah there we go we can go pull remote Branch we already did that in webflix and so if we were to do this again uh we'd be able to do it uh from you know up from the remote let's use GitHub UI to commit a change to our repo and then pull it down navigate to GitHub uh navigate to Classics uh edit
this file add a new line all right so we're going to do this right here watch this one this is going to be a little bit wild we're going to navigate to Classics we're going to edit this one by hand we're going to throw that in right there we're going to commit changes and how do we want to commit these changes I want to make sure I have the correct name just in case to pull the let's see hold on Commit the changes but uh add the message J update classic vs okay there we go
J commit changes boom committed out of my mind all right let's go commit the change using the UI okay we did that on your command line make sure you're on Branch main merge the changes from update d okay so get check out main get merge uh update Dune there we go uh get run get pull origin which will pull in the most Regent recent command all right get pull uh origin main there it goes it P pulled it in oh no I have diverging branches por Maria I'm not supposed to have merging branches yet this
not supposed to happen oh my gosh I have diverging branches I was messing around too much and now look at me now look at me I'm 4 foot2 exactly this is where I give up ah it's not that bad all right so this isn't too bad so oh you should also do this oh did I uh did I do that let's see if you if if you get diverging branches run get config pull rebase false make sure get will uh merge on poll and try again so get status so there we go so if I
go like this get config uh list uh GP rebase do I not have it weird I thought I did did I not have that on uh get config add local uh rebase what is it is it pole rebase pole rebase false it's like I planned I pre-planned for this there we go beautiful right beautiful can we agree with that I did do I I actually probably deleted it by accident there we go now I have a nice merge now I have a merge commit which we you know jeez and so we got a merge commit
with a K there we go there we go we did all that one uh make sure everything worked with get log on line uh get log on line there we go a b CDE e f g h i j k there we go there's my main right there isn't that nice little annotations by the way origin that's where my origin's at or at least where I think my origin's at this is where I'm at this is where my update do at there we go perfect first commit was in fact not bat man pretty poor move
on my behalf honestly not naming my first commit Batman it's really the way you got to do it oopsies I forgot to do this uh assignment switch to a new branch called ad Classics my bad add another line this one okay we'll do uh get switch C uh add Classics this stuff is kind of easy I don't think there's anything very interesting here that's going on that's why we're kind of just moving rather quickly we're going to do a poll request if you've never done a poll request they're really not they're not hard at all
they're very very simple oh my eyeballs there we go by the way did was I supposed to no I don't think I was I don't think I was anyways I just want to make sure I didn't goof up anything all right there we go so we're going to do this thing we're going to add the classics um let's see uh Classics there we go Alfred hitch hok hitch hitch HW Hitchcock Hitchcock uh get status have the classics what do we want to call this thing this is an L we're going to take the L get
add this get commit sorry this this part I I I mean I maybe some people are you know uh find this stuff uh they don't know how this stuff works to me it's very very boring right have you ever if you haven't done any of this stuff it's very very simple and you're going to do this can you do a PO request directly in git well poll requests are something of github's more nature so we're going to be doing a a poll request you can use the GitHub tools you can't do it directly from that
because git does not know about GitHub if that makes sense all right so there we go we did all that and so now I just simply need to push the new Branch at the GitHub navigate to GitHub do a pull request click new polar request set the base Branch to this one add Classics we want to merge this one create the polar request but don't merge it yet there we go very very simple so jump in here get push origin ad Classics notice that I do get push remote Branch you don't technically have to do
that if you set up tracking Alfred hitch HW interesting compare there we go add classics classics goes into main create po request bada bing bada boom look at this beauty right here you can see these two things because we're not quite up to date with all the stuff I'm not reading chat chat is unhinged today absolutely unhinged all right there we go run all checks looking good absolutely unhinged all right my workflow well on this topic of whole request I want to share uh my 90% of the time uh and all let's see I keep
all my serious projects on GitHub that way if my computer explodes I have a backup and I see and if I if I'm ever on another computer I can just clone the repo this is true uh I configured my git to rebase by default that's why we had that you know this what I do uh rather than merge so I keep a linear history right I like the linear history because I just part of what I've always done is I always have this as true it's just you know I it's hard for me not to
get config um let's see local uh unset local what is it it's poll. rebase there we go uh that's this is what I do I just do this I do very simple stuff when I'm working by myself I just add my changes and push it up you know I think when you're when you're working by yourself you don't need to practice all the greatest things because it doesn't really matter right uh when I do my team workflow I go on here and I do the ad and I make sure I rebra everything and I make
sure it's all the ways exactly the way I want it to be and I do all that and then I do the the merging is it a good practice to add it to the global uh I I added to local because I wanted local Behavior here I don't like to do things on the global scope if it's something I don't want done for everything since I wanted to turn off rebase I didn't want to put it globally on in case I forgot to turn it off right so if I go get config global global list
Global list we're GL we're damn Global list there we go uh re re-enabled see I got to turn that off see I don't even have it up on here see I must I must have deleted it on axent get config uh add Global uh poll rebase rebase true there we go push on Save of course yeah it's one of those things that's really hard to REM it's why I try to do whenever I'm doing things like this I do it to the local as opposed to the global because I always end up effing stuff up
just like that I I I take off all these things and I forget to add stuff delete my feature Branch repeat yep there you go so you know that when working solo do I use many different branches in pquest workflow no I don't I think it's a waste of time personally I think it's it's a huge waste of time my workflow while let's see while the topic of PLL request I want to share oh I did this all right when working with the team uh yea Force push no work on a branch feature Branch then
open a poll request for review that's how I do it just makes sense right so if you ever want to commit to open source you obviously need the fork you need to uh create a pull request you need to do all that stuff right get ignore is really really really really really important because obviously node modules if you don't know about them they're horrible uh so you need to get ad commit some message here get push origin problems will arise uh get ignore file just simply allows you to say here's a specific file or a
class of files to ignore you can also go with the inverse which is you can ignore every file and then just add the files you want to have it's kind of like a fun way to do stuff um if you've never done that kind of stuff right and so you could have is this the first or second this is the this is the first part so we're going to create a node of modules or we're going to create a get ignore file that has node modules in it right so if I go like this Vim
get ignore oopsies I already have Vim open here whoopsies we don't want to do that uh I want get ignore and go node modules modules by doing this if I go like this makeer uh Fu and then I go back to here let's see and I go back in here and I go in here and go like this uh bar. MD save that and then I go one more and go node modules and I go in here and add uh fu. MD right bam if I go get status you'll notice something Fu hasn't been added
yet right so it doesn't have any idea what's underneath so when I go get add everything and do this you'll notice that it only adds Fubar it does not add node modules and that's very important and that's because this matched anything it's just a match so you got to be careful careful careful careful include bid and build you coward no another cool thing about G I'm not sure if I talk about this here I'm going to I'm going to go in here and I'm going to erase that right erase that get add this get status
you'll now notice uh node modules is now added right awesome so that means here's an interesting thing I can do I can go in here and go get ignore you can do uh let's see let's go bar anything with the word bar in it get status now you'll notice we have this and it didn't really quite do it I believe I had to go MD exact match can I exact match it get add this get status I think because I already added it it causes a weirdness get restore uh staged uh Fu bar. mty get
status there we go it's gone right it doesn't exist it's already been staged so I had to unstage it there you go so if I erasee this and go back here get status you'll notice that it's now able to be added back so you can actually do inner directory get ignoring which is pretty nice I'm a big fan of that if you want to do it you don't have to do it but it's cool it's cool to know that it's possible and one last thing that you can do as well is there's a file called
um called uh what's it called get info exclude you can see it right here there's the path things that are ignored in here are ignored for your local repo they're not ignored for everybody and so this is a really cool little file right here if you don't know about it I'm not sure if I talk about it but you should like say you like for me one thing I always do is I go like this I always I always have like an out file that I always have so instead of adding it to my get
ignore I can just add it to my excludes and by adding it to my excludes uh when I so you know when I run some sort of program Echo Fu and pipe it to my out file when I go get status my out file just doesn't show up but nobody else has to know about my outs ignore I like keeping all the ignores in one place it doesn't make sense if you're working on a team right when you're working on a team I have a bunch of Stupid Files that I create regularly out out to
and so I don't want to have out files inside the G ignore so I put it inside the git uh git excludes list which is kind of like that special one there's also home get ignore I didn't know about the home get ignore is this like one uh is this a global project uh ignore see I mean G has a lot of features so I didn't know that this is the same as a global level get ignore of your work oh cool all right Perfect all right so here we go assignment create two files in
your repost secure password. text and create a let's see first create this thing all right and create that all right we're going to do that and then guilty pleasures all right perfect get check out main I assume we're supposed to be on the main branch are we on the main branch yeah yeah yeah yeah yeah yeah yeah yeah yeah uh get status uh rmrf Fu let's get rid of all this get status all right get add this get stat status uh there we go oopsies oopsies uh what is it called webflix there we go uh
we're going to here I'm going to get rid of that thing get ignore and go in here oh that's not what we wanted in there we wanted it in secure and then what did he say passwords do text or some crap like that and is that what he wanted password. text yeah and then one called guilty pleasures all right guilty pleasures. MD boom The Notebook let's go guilty guilty AF finally create a get ignore with both with Ensure both of those files are ignored ignore the entire secure directory and then um all right perfect uh
secure and then guilty pleasures all right and then let's see with the message starting with M all right get commit we got to do a little M message uh get ignore uh my uh my notebook Pleasures okay you don't know you just don't even know how good the notebook is all right there we go Nest to get ignores oh I actually already went through this we actually talked about this exact thing didn't we oh my goodness we already did this all right which is ignored all right hold on what are we doing here here's the
let's see here's the contents all right we have these contents uh here's the contents which is this Source assets get ignore which is going to be only devs and main.py and this one's going to be Vin bin activate so that one's going to be this one uh right here and this one's going to be only Dev and what's the other one main.py and main.py okay here's the here's the contents wait hold on what's the question which is ignored they're all ignored aren't they all ignored aren't they all ignored does not necessarily have to be at
the root it's fairly common to have this one am I am I misreading things I mean this one will be ignored yeah this one should be ignored and this one should be ignored okay oh oh yeah of course not I'm so stupid okay sorry I'm so stupid this one's um main pie which does not exist at this level okay I wrote this I actually wrote this this one won't be ex and then this the grot one has ven has ven V been activate which this one should be ignored as well right am I wrong here
shouldn't that one be ignored just equally whatever there we go only devs I want a main cupcake you can't have one wrong what am I missing there sell Boozled yeah it's not one of the options oh act let's see activate is a shell script not a folder ven is in Source oh V is in Source my bad okay I just wasn't looking hard enough okay your G ignore file does not necessarily need to be at the root of your project I haven't looked at this in a little bit okay I wrote that to try to
be clear uh it's fairly common to have multiple G ignore files yeah um there you go we've already talked about this one here's the Let's see we have already done this one which is not ignored okay so Source ven bin this one okay this makes sense now we got it uh test. Pi which one let's see test. Pi that one's not even in there there we go we got it skill issues I'm skill issuing come on shut up uh it would be rough if get ignore only accepted exact file path sections luckily uh they don't
let's go over some wild card common patterns dude the star that's the one that's the one that always works I do it constantly root patterns uh patterns starting with the slash are anchored to the directory containing the get ignore file for example we ignored main Pi in the root directory but not any subdirectories with that negotiation or negation you can even negate patterns with prefixing with an exclamation mark this is useful if you want to ignore an entire directory except say an example file I find that to be really really useful is that that kind
of move right there I I really do like that you can do comments that's just like typical shell comments but how do you make a use of multiple G ignores save some notes or something uh if you want if you just want something ignored a certain way you can do that I found it really useful when it came to uh monor repos so if you've ever done mono repos in uh with like node or something you want to be able to have a get ignore for each one of those repos it seems to be really
nice that way so yeah data directories yeah exactly you just have like these little get ignores so that way you don't have one giant get ignore that's super hard to figure out what the hell is happening instead you can just do that so it's nice all right assignment use this get ignore file to answer the question uh all right so that's a comment we're going to ignore everything with a with a text file except for the ones with name and then we're going to do Source Main and then content Source content is ignored so this
one is ignored Source content MD because this one is an exact file name that matches this one and it's not anchored so it should be is ignored let's go patterns it would yes we already talked about patterns we already did all this uh what's the other question all right Main JS is main.js ignored no it's not cuz that's a comment it is not ignored let's go nice try trying to bamboozle my own questions all right here we go they're trying to bamboozle me all right assignment Part D we'll do that soon all right here we
go Let's ignore a generated file we ignore generated files because they can easily be regenerated from stuff we do track in this case we're going to use pandoc to generate HTML from markdown files we'll ignore the HTML files uh but commit a markdown file first install pandoc Brew install I don't have that but we do have this guy I can't show you guys this screen all right here we go uh there we go look at that look at how good that is look at how good that is fantastic there we go we installed pandoc we
can run pandoc version to see what that is so I can go like this um uh pan up uh hashr pandoc uh my password is big boobs everyone knows that big boobs 69420 all right here we go running pandoc all right create a new file at the root directory called advert MD with the following content all right so let's do advert that one while supplies last there we go uh Vim at oh uh let's go to this one Vim advert MD paste all this stuff in there we go and then run the markdown let's see
run the following command to generate the HML document from that there we go pan doc Bop get status so now we have the we have this one advert HTML beautiful uh for Fun open up the markdown HTML and see what let's see we can do that XD I don't want to do that we don't want to do that because I had to go like I don't even think XT xtg open does that work on look at that look at that Beauty look at that be would you look at it would you look at it there
we go uh we're going to do we're going to do a get ignore I think I have to do a get ignore here oh it doesn't technically say okay see finally add the file oh the get ignore there we go uh Vim uh get ignore what is it called it's advert HTML bam get status up get stat get status so I think I should be able to do that nope do I have to add stuff finally add the get ignore oh and commit the change serving with 10 get add get status get add get commit
n was it n yeah Foo bar screw it got him there we go I finished it we finished the entire course just like that I'm level 12 you would even understand what level 12 is you wouldn't even understand it uh what's your opinion on how organization should handle PR merges in main squash uh merge merge commit or rebase which is most useful when you are responding to an incident which is the most useful for Dev happiness overall in a proud environment well I mean here we go again I know here we go again damn uh
I'll here I'm GNA I'm going to say it this way I personally like to rebase and squash I like Fast Forward merges I like to be prepared for the eventuality I need to uh revert a changes that's it now some people it depends on your size honestly if you have just a couple people like why even have a policy I'm going to be real out there why even have a policy at all some people like to rebate some people like to merge screw it let it all happen do you really want to set up a
whole bunch of red tape for you and one other person like why why why add more to your life here I'm going to throw something out here no matter what you choose merge chaos fast forward merges only rebase squash no matter what you choose there will be a group of people that complain about it so we're going to start this one so this one is a little bit different okay this one is a bit different this one is going to go over a bunch of like conflicts and stuff okay hey I know you're about to
take learn get to and I really wanted to show you a couple quick techniques to make it a little bit easier because inevitably you may mess up at least some of you are guaranteed to mess up you didn't read the instructions well maybe it's not quite as clear as it needs to be and so these are two little commands that are going to help you a whole bunch so the first thing I'm going to do is I'm just going to show the contents of the previous commit that's going to show Foo with a message of
Fu 3 now every now and then you may have goofed up a little bit with your commit message and you just want to change it you can go get commit amend this will give you a chance to change your message but as a warning it does change your Shaw so obviously this is a destructive history altering item it allows you to change the last commits commit message so if I go like this get log one more time you'll see now it's Foo 4 and you can see that and if I go get Foo let's see
if I do two of these you'll notice that there's not a foo three three in here anymore looking at the change you'll see that all it is is a new file called Foo previous file was Devol meaning there was no other file so it's just a new file called Foo with a single line called Fu now if I actually want to undo this commit completely I can go get reset soft head TIY 1 this will undo that commit so now if I go get log just one line you'll notice it's not that anymore but because
it's soft and it leaves changes in your index and work tree if I go get status you'll see right away new file F okay we can work with this get reset hard would not only undo that commit by one it would also remove the file so if you ever have to say change something within a file or you need to change the commit message consider get commit amend or consider get reset soft now I use actually get reset soft quite a bit when I'm doing a rebase merge conflict this does happen every now and then
where I'm rebasing and I go okay I fix all my changes and then I actually get commit those changes as opposed to calling get rebase continue if you make that mistake you can actually use get reset soft head till one to undo that commit and then rebase continue it's kind of like a you know it's like a it's a lot of IQ and it's really really nice so I just wanted to give you those two tips because honestly this course can be a bit meaty and without these two things kind of fresh in your mind
you might accidentally find that you get your yourself into a bad State and it's hard to undo it's actually pretty easy to undo these bad States the name is the gagen all right here we go let's do this let's get going okay welcome to G part two I wrote this also where you learn how to use G with a team if you haven't taken the first G course I'd recommend starting with it because it contains all these basic operations okay uh the stuff in this course is great let's see the stuff in the first course
is great if you work by yourself but you'll need more if you want to stand a chance as a developer Mega Corp where we sell synergistic CRM customer relationship Management Solutions to Enterprise that's right we do hey look I'm wearing the same shirt I'm wearing the same shirt what are the chances uh this course assumes you've completed uh number one so you'll have all this crap that we've already done we have already blah blah blah blah so we've already done that thing same shirt what are the chances there we go I'm just going to run
this because we've already done this okay we've run it we've done it you need your own Fork of Mega corpse starting repo a fork is a copy of this one so we need to go here I'm going to first need to jump in here I'm probably going to need to uh can I fork or is it not going to allow me I can't tell if it's going to allow me or not nice let's go I've done it please select owner Fork already exists shoot okay it's K sensitive today I learned it's K sensitive there we
go I thought I just deleted that but apparently I didn't delete that there we go and create all right we got the fork we're forked out of our mind all right let's let's let's do this let's do this all right so we got a fork we did that we pressed the fork button we did hey look at that hey look that's me hey that's me doing that all right boom boom boom boom boom boom boom run check pasting your link we're going to paste that link all right there we go all right what is a
fork uh we created a fork of the official a Corp repo inside your giup account it's a copy of the original that you can modify without affecting the original you may have noticed that there is no manual entry for get Fork git Fork is not a real thing right why forking is not a git operation but is a feature offered by many GI hosting servfaces such as GitHub gitlab and bit bucket those Services Fork a repo by creating a new copy of the repo and associating it uh as a fork of the original there's something
called like a fork Network or something like that with GitHub which is very confusing it's like one Super Repo and there's some sort of thing that they do underneath that's a little bit more confusing this is gamified git tutorial this is a g tutorial I wrote and I'm going through when you Fork someone else's repo on GitHub you simply clone their repo into your local machine you create a new branch of The Originals well technically I think it has something to do with this in the fork creation network but I don't really know how it
works create a copy of your own let's see of the repo and your own GitHub account boom let's go that's what we did all right I'm not working TC no okay GI Fork is a command line operation that takes no f false all right now let's clone it down let's clone Mega Corp uh RM RF let's get rid of webflix let's get of webflix local let's get of uh Mega Corp Mega Corp uh get clone the primagen get clone get clone primagen Mega Corp Bim we're in we're in we're in in there we go perfect
all right we're we're in okay so let's get let's let's start doing this whole thing because this is this is the one that in involves a bunch more stuff uh when you Fork someone's a repository like a platform like GitHub you can copy a repository into your account this is the standard way to contribute to someone else's open source project uh steps are typically Fork the repo to your account clone the fork to your local machine create a branch or feature make the changes commit the changes create a poll request bada bing bada boom you're
probably asking yourself why should I Fork a repo instead of cloning it cloning is a lot easier well that's a good question you first have to answer the question am I interested in contributing back to the main line or do I just want to peruse the repo if you wish to just simply peruse the repo then a clone is just fine whereas if you wish to contribute to the open source project then it does require a fork here's usually my workflow when it comes to forking and making changes one I just Fork the repo two
I will clone down my forked repo three I'm going to make the changes to my main branch four four I'm going to push my changes up to my Fork's main branch five I'm going to open up a PR with my changes from my Fork onto the original repo along with a nice detailed explanation of what I have changed and why and finally I get rejected go home cry a little bit skill issues but nonetheless I tried and that's what really counts doesn't it it's also worth noting that whenever I clone down my Fork I also
add a second remote that I call Upstream that points to the original repo and the reason is that when the original repo changes I can bring in their changes and that way when I fix something I know that I'm fixing on the latest version I'm Not accidentally fixing something somebody else has already fixed this also avoids having conflicts during PRS and if you wish for your PR not to be rejected here's some pretty helpful hints number one whenever I make a PR before I hit that button and say make it live to everybody I review
my code on GitHub this weird thing happens to me whenever I review code on GitHub I seem to catch things that I don't catch when I'm in my own environment I kind of think of this as editor blindness you're so used to everything that when you see it in a concise different way you just see mistakes you've made so much easier probably most importantly is make sure the maintainers want these changes spend the time looking through the repo issues make sure you've searched and validated that this really is an issue and if there's no mention
of it open up an issue tell the maintainers you're willing to fix it and see if they want you your fixes you may find that maintainers actually do not wish for you to participate or others they may want you to fix it but in a completely different way as long as you're polite in your communication and you're very clear as to what you're trying to fix you will find that often maintainers are very happy to have you come on board and help out okay so assignment I want to make sure people know how to do
this okay I want to make sure people knew how to do this like fun little bit add a file in your forked and cloned version of Mega Corp to the repo uh to the repo contributors directory uh the file should be named let's see your get up username text replace your username with a good one okay let's see add myself to the contributor okay Bam Bam Bam Bam Bam Bam Bam Bam let's go in here and go here okay well I'm already there the primagen 2. text oh my gosh oh my gosh all right there
we go there we go we got that let's do that let's go like this get add uh uh get whoopsies all right there we go so we're going to push this up right so I'm going to do all this I'm going to push this up push my changes to my GitHub uh to an add contrib Branch oh gosh get checkout add contrib oh I'm not supposed to use checkout sorry it's just I can't help it I can't help that I do who the hell does that who Noob Noob Noob he's a noob I'm not even
sure oh I I copied it from the boot. dev site remote add origin all right there we go fixed fixed you wouldn't understand understand fixed you wouldn't understand you don't understand because you're you're you're sore loser boom I think it told me to create a pull request let me just make sure that that's what we're doing here all right there we go all right with the poll request open submit the test all right there we go run all checks let's go owned it head mean where me at now for those that don't know who grug
is grug is the best I always go down here and just I just read this line whenever I think of gr grug apex predator of grug is complexity complexity bad say again complexity very bad you say now complexity very very bad given choice between complexity or one-on-one against T-Rex grug take T-Rex at least grug see T-Rex complexity bad all right let's go like this okay for example you should be on main branch of your local clone of your fork of Mega Corp repo which which means head is pointed to the main branch like all things
and gets eternals head is just stored in a file right here manually uh check to see what's in head yeah let's do that cat uh get check out main get cat uh dog I think it should be I think it should be the name of the thing there you go yeah it's just a it's just a path path to the uh to the branch or the tag if I'm not mistaken G yeah you got to G it baby you got to G it get that son of a bee all let's see if that just works
okay what did I I didn't read all right what's the thing oh uh get Branch d add I must have missed deleting that did it say to do that okay my bad I didn't look I did not in fact look we're going G grug no read all right get reflog command pronounced a reflog not reflog is kind of like Get log but stands for reference log and specifically logs uh the changes to a ref that have happened over time T the default one is the head by the way grug no read grug never read where
head is now one move ago two moves ago three moves ago you are already familiar with how git log Works how it shows your current branch and all the history of the commits so if I had a brand new repo with three commits a b and c and I execute log I should see the following output and if I execute ref log I should see this following output is reflog just a verbose log well no it's actually not it's very very different and to illustrate the point let's remove commit C I can remove commit C
by using git reset I can walk back one branch and as you can see with Git log I now only have b and a but if I use get ref log you'll notice that I don't have two entries I actually have four entries I have a b c then back to B and notice that it contains the command I use to get to B which means that if you need to get the contents of C you can actually use some of the plumbing of git plus reflog to be able to retrieve back out the contents
of C even though it's gone from your branch I cannot tell you how many times reflog has saved my bacon by walking back and getting some commits that have been long forgotten so what is reflog well the definition from get SCM is reference logs or ref log records the tip of branches and other references whenever they are updated or in layman's terms reflog tracks the changes of a branch or other references other references being head this means as you move your head around from Branch to branch or from commit to commit it tracks every last
little step I personally only ever use reflog to look at how my head has transitioned over time and Rescue out of commit if I need to all right assignments run get reflog to see what its output is all right here we go get ref log look at that look what it is going from ad contrib to main from uh from Main to ad contrib to this commit to the Clone cool right you get to watch it kind of move around it's kind of cool I like it reflog is nice and it's really not all that
bad all right switch to a a new Branch off of it called slander get uh switch C slander look at that I remember to use that uh let's see create a new file called slander. MD and have this one all right Vim slander. MD paste that in uh Mega Corp CEO Lane enjoyed the live action last air bender movie this Mega Corp CTO Prime is a fan of the notebook okay Lane mayor or may not had a little bit of fun editing some of these things okay I don't know if I didn't choose all of
the stuff I'm just saying you know the notebook's not a bad movie okay what I feel I even have to commit it okay it's not it's not bad okay it's not bad Ulta movie was a good terrible movie too did you cry I didn't cry I'm not crying SL slanderous slanderous filth I'm not even sure if I spelled slanderous right um boot. Dev run that okay what am I not even doing here all right expected this contains all this one oh I had to do b. slander goodness gracious uh reset soft uh head I okay
I got to start reading you guys are not helping me um uh be slander you guys got to quit but by the way did you see that nice usage of get reset soft huh ha did you like it I could have get commit amend I could have we could have amend but this one is great okay it's okay it's okay to cry it's I don't cry I work out I know we could have amend okay but we didn't okay delete Branch every ever uh shipped a bug to production main branch created a new Branch to
fix it bug fix fixed the bug and committed the changes switch back AC deleted deleted the fix bug Branch all right switch back to Main and delete your slander Branch get Branch D whoopsies get check out main get Branch oh I'm supposed to use switch but I I just I can't I cannot use switch okay I can't use switch I can't I can't use switch all right I want to use switch Boomer brain I know so you've deleted your branch that had a unique commit On It All Is Lost or is it remember get reflog
keeps track of where everything has been so let's do this get ref log look at this bad boy that's where we did this one look at this commit right here the commits right there the commit is right there okay that means what we could do like here's one one way to do it which I'm not saying this is the way you should do it I'm just saying this is one way you can do it you like this you can go like this you can go uh get cat file- P remember when we learned about all
this and you can actually go through all of the little internals and snatch out the slanderous file get cat file- P look at this right there there's me enjoying the notebook right we were able to Plum through things if you wanted to if you wanted to get deep in there and kind of go through the whole thing you could so there we go we grabbed that and so we can actually grab this and do that and do a recovery message right so I could do this right there's other ways I could also do stuff right
this is just one way you could also get merge and since I already have this thing I could actually just merge over that change into it we're not going to do it but you could imagine we could do that so instead I could just take the contents of this one file and I can remake it if I wanted to as well even though it's not true commit that file with B recovery get add this commit dashb Rec recovery Boom Confetti out of my mind all right cherry pick would have been what I would want to
do really I would have just merged it over right I mean it it just depends do you want the history or do you not want the history like what happened if there's 10 commits then you have to cherry pick all the commits let's see using get internals is exceptionally inconvenient we had the copy and paste from cat file three times I would not recommend doing it this way I just wanted to drive home that at this point you can always drop down to the plumbing commands if needed luckily there is a better way get merge
I just haven't talked about Cherry commit that's why we haven't talked about that so I can do reflog this one find the commit kit that one so I can do get cat file do all this crap which we don't want to do I can also do this right right I could have just merged over exactly what it said from reflog right let's see do I still have that reflog thing or did it open it in one of those windows uh I think it did that one of those windows right yeah do I do no pager
no page I can never remember what that line is oh that's right you don't do it there it's a get no pager there you go so as you can see you can see right here so I could actually do get uh head at the second position back right why does get ref log allow us to potentially recover commits on deleted branches because it keeps a record of where the head has been yes that's what it is there you go little fun little fun reflog stuff merge all right let's see what can you merge with only
tags commits branches a commit commit tag ref log entry anything that can resolve to a commit so that's why you'll see me use the term commit quite a bit in this [Music] course all right uh working with Git is a dream when all of the developers in the project are committing changes to different lines of code things get a little hairy when changes are uh to the same lines are made at the same time one commit isn't the parent of another let's break some stuff remember Mega Corp is Enterprise CMR Service uh backed by the
power of git Essen it means that we store lists of customers data in a get repo truly Cutting Edge stuff you should be on the main branch uh create a new branch called add customers all right get branch no wait it's get is it get switch see there we go all right there we go we got that one and we're going to grab this one uh to customers a CSV all right all is it all like that one yeah there we go so we're going to add it to all customers and then we're going to
also do orgs partner. text right there Boot and startup so we're going to do orgs partners. text there we go beautiful we've done those two make commit your changes with the thing C okay we're we're going to kind of cruise through these easy Parts because I assume at this point you guys understand adding committing doing all that um because this is all easy stuff right none of this stuff is crazy all right get status get add this get commit I think I said c right yep see uh uh such Carson much HDMX all right there
we go and now we're going to switch back to Main and we're going to do this to customers uh get check out main uh go back to here edit this thing jump up here customers all add Json gross HTM Z contributor get add this get get commit what do we need to do with d That's right d uh Jon is better than uh Carson more like cars off all right so do you do you see what we've just done here do you see how this is going to cause problems so if I go like this
uh get log uh on line um on line- P1 main you'll notice that I edit customers with one line right below company title if I do the exact same thing but I do it uh with the add customers Branch you'll notice that I do the exact same thing to the same customer files in the same location in other words we both modified the same line and by modifying the same line G doesn't know what to do because git doesn't understand anything about code it only understands things about modified lines if two lines have been altered
in some way it creates a merge conflict there we go I believe that should just work there we go and let's go conflicts yeah yeah yeah yeah yeah yeah yeah so merge conflict occurs when two commits modify the same line and get automatically decide which changes to keep and which change to discard consider the following commit history ABC this is pretty much what we have now except for it's a c and d uh the main branch has something like this uh is nice returns this one feature has this one is nice 420 right if we
try to merge feature into main G will detect that the return line was changed in both branches independently which creates a conflict so this is good this is good to understand right when a conflict happens usually as a result of merge or rebase git will prompt PRP you to manually decide which changes to keep it's okay when the same line is modified in one commit and then again in a in a later commit the problem arises when the same line is modified in two commits that aren't in the uh in a parent child relationship all
right if the line changed in B was all the conflict change in B's parent a the htx guy writes an essay about it that's true Carson will probably write an essay about it uh that's perfectly fine get knows a happened first then be yep that's the thing you can't conflict yourself like that right you just can't all right if two developers on separate branches modify the same line of code what happens when the branches are merged HTMI htx guy relaunches the project with a new name facts it's perfectly fine false conflict arises there we go
assignment it was stupid Greg stupid Greg who merged his new customer data into main commit D while you were working on your new customer data in ad customers Branch commit C because his change made it into main first stupid Greg it's up to you to resolve the conflict stupid Greg now because your manager is a lite that learned a code before Version Control was invented he asked you to merge instead of rebase absolutely this is all true switch to your add customers branch and merge main into it all right there we go we should get
this one let's go let's go get check out add customers hey uh get Branch d add uh add contrib wait why is contri still there I thought I just deleted it why is there why is there multiple ad customers whatever that's confusing whatever I don't got time for this damn it Greg leptos mentioned leptos potentially mentioned get merge main all right boom we got ourselves a conflict okay uh if we run get status you can confirm that we're in a conflict so if I go get status you can see right here you have unmerged paths
fix the conflicts and run get commit and use a get merge abort to abort the merge so we can actually stop the merge by doing that get out of here okay there we go get run status like this to confirm that you're in a conflict we can see that so let's run this thing boom Oh wait what oh my gosh this thing is incorrect lane lane Lane we have a problem this is this is wrong our Direction somehow got out of conf out of out of stuff here I know which means I go like this
get uh merge abort get check out main get merge uh get merge uh add customers there we go kind of BS Lane all right right here I'm going to go back here I'm going to report this uh wait does it am I wrong here did I just maybe I just didn't hold on get uh merge get merge aboard get check out maybe I did this wrong yeah I used the wrong one lane it's not right lane you're right you're right this whole time I'm the bad one I'm the bad one I'm the bad one shut
up get check out you dumb folk I know I messed up isolate to changes and merge correct you merge yourself correct resoling conflicts is a manual process when they happen get marks the conflicted files and ask you to resolve the conflict by editing the files in your editor so here we go open up the customer all and you should see this all right so here we go here's our customer so you can see two you can see a couple things here just so everybody knows in emerge conflict this represents uh hours is the top one
hours is where our head at here's the change in hours the change ends with the equal sign and then this is the one and then the bottom one represents the incoming Branch theirs so theirs is main ours is head and this is the change in theirs this is the change in ours okay it's pretty good to know those things right uh let's see delete the conflict Mar markers and leave both changes and Greg's changing the file it should look like that so we can actually you can actually have both changes at the same time right
nothing says you have to change it it's up to you to resolve how to to do this you can accept both totally reasonable uh sa file and do this okay yeah we can we can accept both there's nothing that says you can't accept both right all right resolution after manually adding any conflicted conflicting file sometimes it's more than one file or more than one section of a file you simply need to add and commit the changes this tells get that uh you've resolved the conflict and can continue with the merge okay awesome we can do
that so let's let's resolve with this nice message right here it's a nice beautiful message get add this get commit uh- M all of that oh my goodness stupid Greg oh no all right there we go apparently I don't know how to do that there we go got it first try and now we can do log to examine the homework you should see c and d and commits come together and E commit all right get uh log on line look at that beauty and then we can go on line graph there you go it all
comes together in E we resolved the conflict bada bing bada boom very nice absolutely liked it absolutely enjoyed that all right all right you just ran get merged and you're now seeing this okay I just realized what was happening I was like wait a second uh which code in the conflict is yours and which is theirs so if we ran get merge that means this is ours this is their theirs the top is the top is mine the bottom is theirs it's all mine stay away I prefer that answer honestly um all right you just
ran get merge and you're now facing this conflict oh let's see what does head refer to it's another name for the master branch no it's another name for the main branch no it points to the latest commit in the other Branch you're comparing to no it points to the current Branch's latest commit boom it's pointing to where head points to everybody knows that is that easy back to me your manager at Mega Corp is not happy it turns out you were never supposed to add customers to the all. CSV file at all only Greg is
allowed to do that stupid Greg this is what you get from making changes without 10 design meetings and an alignment of stakeholders what were you expecting to be productive this is Mega Corp process over productivity get back in line I don't want to hurt anybody's feelings but at the same time I know a lot of people just got bruised by that one statement I'm sorry I'm sorry that right there's some of you that hurt that paragraph hits home I know it does let's just say I've written a design document for the the dumbest thing stakeholders
are okay in the 10th design meeting but have problems when the implementation hits BR always every single time assignment let's fix our hastiness by uh doing a git hard of the merge commit this will allow us to take a different approach to resolve the conflict luckily we haven't borked main yet we just uh need to fix our ad customer Branch while on ad customer Branch reset to commit C all right let's do that oh my goodness um let's go like this let's go what is it called Mega Corp yeah yeah yeah get reset uh hard
uh head till the one there we go we're back to C everything is great we're looking good we're feeling good there we go we do all that nice stuff so I just I I literally just took the change moved back my Branch ones and discarded my index my work tree changes bada bing bada boom easy peasy pumpkin seedy that's just that all right uh let's fix our hastiness by doing a hard reset yeah we already did that luckily we haven't borked main yet so we'll just uh fix all right here we go try merging main
into customers again this time resolve the conflict by keeping only the changes for main I want to see something cuz I may accidentally have uh R re on and if I do then it's going to say it's all fixed nice I don't have R re on uh get config list uh Global grap re re oh I do wait shouldn't re read take care of that doesn't wouldn't Riri re jump into that am I confused here am I be what what I thought it did well then why didn't it it should have Auto conflict it record
yeah record resolution was solved was added weird Why didn't it just Why didn't it auto resolve right here shouldn't have just Auto resolved oh wait oh oh my goodness I am so stupid I am so stupid it did it automatically using previous resolution so if I go to customers oh my goodness I'm so dumb look at this the conflict is gone the reason why the conflict is gone is I knew I had re re-enabled so since the customer doesn't have a conflict in it we need to disable R re get uh config I'm just going
to do a local one uh I'm just going to go like this add local re re re enabled false right so I'll just add a local one so I still have my Global one so it still continues to do what it's doing uh get merge abort then get merge um get merge main which should now there you go I now have the conflict without re taking over and I should be able to just go into here uh and I should be able to go to all and now we have this again so now this time
we're supposed to select Greg's change which is theirs so I can go like that boom Greg's change selected uh there's some other ways you can do that to make it easier but this is good so we're going to go like this find Greg have this one boom uh we're going to go here and go get St status get add this get commit dasm with that one there we go um and then jump in here do that there we go there we go all right I think that's good all right ours versus theirs uh in a
merge conflict ours refers to the branch you are on merging into theirs refers to the branch being merged this is important get merged their Branch ours is the branch you're on right uh get terminology last time we manually edit the conf uh conflicting files this time let's use get built-in merge resolution tools to make the uh let's see use the terms hours and theirs to refer to the branches being merged you should currently be on ad customers with this kind of History right now switch back to Main and merge ad customers into main this would
result in a fast forward merge bringing C to e into main delete ad customers all right get check out main get merge add customers get Branch delete uh add customers boom look how fast I am all right so let's do a better let's do an ours versus theirs merge because this is really good to know uh all right so we got a multi conflict so far we've only dealt with one Conflict at a time that's a small that's small potatoes let's see what happens when we have multiple conflicts to resolve all right so let's switch
to a new Branch off Main called delete records uh get switch C that uh and then let's see edit customers all and delete the jesson line okay there we go deleted it edit org partners and delete the boot dodev record okay org Partners there we go boot dodev record boom Oh we want to keep the line there we go uh let's see six let's see switch back to main uh and edit customers oh commit the message with f we got to commit the message with f get status so I'm going to I'm going to use
uh I'm going to use what's it called fugitive for this part cuz it's just easier and faster and you guys don't really care about committing right what do we need to do F uh F uh uh delete those records right I just prefer that uh get check out main just makes life easier being able to use that because we can move faster there we go uh all right so we have this one so edit the ORS partner and add a boot dodev record uh to Sales Inc oh change it and change the boot to Sales
Incorporated yeah yeah yeah yeah yeah yeah yeah yeah so I can go like this Sales Inc um there we go we did that one so now we should have this one and do a g there we go and uh ccg uh such Inc there we go we now have that one run and submit the test there we go wait is that all we had to do did I miss something I thought I thought we were doing multiple oh we forgot to do that we forgot to do that one we forgot to do that one Carson
uh gross that's right all right uh customers all and go Carson gross go here s there we go so I just all I did was I just did right there for those that don't know I just did a uh I did a get uh commit amend no edit and so by doing a get commit amend no edit I simply just um I know I wrote shut up shut up it just means I merged in that change right so I merged in that change right there and I did that one you know cuz I'm not going
to lie to you it is very nice to be able to use the tools I'm used to you know what I mean I don't always do everything by the command line there we go all right so we did all that one we have these nice commits now we have these two things and so now all we have to do is just cause the conflict let's go wait what did I do oh oh my goodness here I forgot to do that there you go I'll show you what I did get status so I have this one
get add this one get commit uh amend no edit there we go so I kept the same the same uh line just not everything else wait what am I doing wrong here Carson grow hmx Creator what I'm not good at reading I'm not good at reading okay I've never said that I was good at reading all right first try let's go first try check out the conflict we've manually edited files to resolve the conflict but it turns out git has some built-in tools to help us the git checkout command uh let's see can check out
the individual changes during a merge conflict with theirs an ours flag while on Main merge delete records all right get merge delete records so now we should have two conflicts you can see the two conflicts right here get status you can see the two conflicts right here unmerged path both of those get diff should show each one of them having the problem right here which means that I can go like this uh how do we do this we're going to keep theirs for customers all and keep ours for partners so I can like this get
check out theirs uh that's going to be uh customers uh all there we go so now I have uh theirs and then ours is going to be orgs uh Partners there we go so now if I go like this get uh diff you'll notice that we have no changes everything looks good get status perfect get add this if we look at them in here you'll notice right away there we go so that's the deleted one that we kept and then from orgs and partners you'll notice that we have Sales Inc from our side so Sales
Inc from our side deletion from their side by using uh get checkout there's an ours hours it's pretty nice what do we need to do here we need to do this with an ah uh M uh H uh let's see such uh resolution conflict you'll also notice something else notice that orgs is not a part of any changes here do you see that there's no orgs a part of changes that's because that wasn't changed by accepting my change this commit doesn't contain any change does that make sense because that file only had one change to
it which was my change so by me uh accepting it the difference between these two goes to zero it's good to know so that's why sometimes those things can change and it can look a little bit confusing it's actually not all that confusing it just means that something goofed up oh my goodness how am I so bad at this oh yeah let's go all right something you may have noticed when resolving merge conflicts is that you don't get the standard merge uh merge commit message right no you don't you have to manually provide a message
typing uh it actually makes sense when you think about it g doesn't know what you did to resolve the conflict and it's encouraging you to document your change via the uh message that makes sense right I think everybody understands that uh what commit message is used after resolving that the standard one unhinged commit message for example we should have rebase instead I actually like this one that's my favorite one but we'll do a custom commit [Music] message now we're going to do rebase one this one's going to be a good one all right rebase uh
full disclosure a lot of rebases bad rep comes from conflicts fear not it's nothing you can't handle with just a SCH smidge of practice rebasing feels scarier because it rewrites get history which means you are not if you're not careful you can lose work in an unrecoverable way but as long as you understand what's going on it will make your and your teams get history cleaner and easier to understand and more so easier to revert when needed it is impossible to revert your change with several merge uh merge commits and all that I've seen some
pretty nasty ones where you're trying to do that assignment create a new branch called band a copy of main branch and add a new file customers band all right there we go scabi toilet merch when get checkout dasb band I didn't use switch didn't use switch it happened it happened but we're going to get keep on going for it band. MD is that what it was no uh band. CSV boom put it in yeah Sam Sam controlman closed AI classic really true AB absolutely actually true there we go so we have this one we're going
to do get message I so I'm going to go in here c c i uh control man there we go and so now let's go like this get check out main do one of those and then how do we want to do here we want to have the same Sam controlman but a different but a different one of these there we go um and then jump up here and go c h oh no wait J you're right H comes before H before I except after C's right is that how it goes I'm on chapter 7even
section four right now all right well let's go let's go all right so there we go so we have all this one so we should be able to run this to make sure it's all actually the way we want it to be so I'll go like this we'll run this bad boy it's going to do all this bada bing bada boom bada bing bada boom all right beautiful we are just crushing through this course okay people were feeling good make the conflict before we move on I just want to remind you that it is often
uh not often that you'll be creating your own conflicts we're doing so because you probably don't have any friends to practice with I don't actually Kid Art users uh but even if you do have many developer friends let's just make all the changes ourselves so you don't need to bother them let's see you switch to a new Branch fix bug which is just a copy of main while you're fixing the bug someone else merch is there changes the domain you fix the bug and it happens to edit the same file uh you open up a
poll request rebase fixing domains get tells you the conflict you resolve the conflict you uh complete the PO request this is like standard operations right we all know this one so we switch the band Branch rebase uh it into main uh which rewrites to get history of band Branch because remember it needs to add that extra commit so there we go we're going to do that all right so we're going to go like this get check out band right there get re rebase main my gosh we have a conflict look at that conflict oh no
oh no so if I go in here I look at my status you can see right here we have problems don't we we actually have problems all right well uh you should get a conflict you might also notice something odd this time head pointed to Mains change rather than bands change all right so let's just jump back for a quick second and just validate this and I'll explain why all right so notice that this should be band protagonist should be main look ate has protagonist which is Main's change why is ours Mains even though we
did a rebase on band why why isn't hours hour change why is it Maine's change does anybody know the commit comes from Maine no cuz that would make it' make it theirs we move to main then replay our commits on it boom let's go so this is from section one this is why section one is so important is when you rebase your target Branch becomes your branch that you're on and then you replay the source branches commits starting from the merge base and forward at the tip of your target Branch therefore let's write this out
because it might be a little bit easier to visualize so this is the most important part remember so when I'm on band and I do git rebase main what happens is I actually check out main which is going to be at the tip I grab the differences between uh uh what's it called band and Main and then I do band you know if there was multiple commits I'd actually attach each one of them to the front so that'd be like band one uh band two uh band three right so I'd get them all on there
so my Branch now looks like this where the tip of main is now the new merge base as opposed to wherever I branched off before which could be somewhere in the history so that is why ours is theirs and theirs is ours during a Reb rebase conflict it's actually not confusing if you know how rebase works it makes perfect sense it's that you have to switch branches and then play the commits all right let's see what happens here let's let's see what our assignment is switch the new branch do this uh copy of branch and
add the new file customers this this this this this we've already done this all right there we go assignment switch to band rebase on domain while uh you should get a conflict you might also know something outd we already talked about why if you had merged main instead of rebase head would still point to band correct because merge does not swap replay it just adds or creates a merge conflict into a single point there we go that's good to know however you kind of need to think in Reverse with rebase theirs represents the band Branch
uh which in reality is our change so we're going to Branch you'll notice that you're not on a branch that's right that makes perfect sense right because remember it has to create this no Branch situation where it takes Main and then starts applying commits to it so you're in a no Branch situation right there we go bam look at that look at that confetti man first try first try uh the same get check out theirs and get check ours uh commands we used in merge can be used to resolve conflicts during a rebase you may
have also noticed that if you open the file in your editor depending on your editor uh it has UI features to help you resolve the conflict yep so this would be uh VSS codes accepting incoming changes is the same as checkout theirs accepting current changes is the uh is the same as get checkout ours that would be in theirs I don't know how I don't know how to use I don't know how to use vs code all right assignment uh use the appropriate get checkout command to overwrite the band Branch's changes with the changes from
Main so since it's main that we want get uh status get checkout out hours our Branch remember we're ding main all right there we go uh let's see then hit him with the rebase continue get rebase continue There we go and then we get logged to see the new commit history get log look look at how good that looks look at that look at how good that looks all right you may have noticed something did anyone notice that I was gone why was I gone so theirs is main no ours is main during that situation
the the number of rules indicates that this isn't intuitive no it just means that it can be potentially complicated anything that is sufficiently complicated requires you to learn if you only worked on things that are intuitive you would never use recursion like that's that it has nothing to do with it being the the number of rules have no indication whether it's intuitive or not understanding the underlying reasoning why or what happens makes it intuitive to understand I understand how you or rebase Works therefore ours versus theirs is intuitive to understand but that's because I have
a understanding of what's Happening expected a state to contain this way H uh Branch oh I'm not oh I haven't uh oh uh get rebase continue oopsies did I not get status did I not there we go we've continued it gets status awesome all right let's do this perfect we're in we did why did the deleted command what happened why was I gone so for those that don't understand so why where's I why is I not in here the reason why I is not in here remember this is that I was a change where deleted
deleted a specific record and what we do we ignored that one change by ignoring the one change that I was we've dropped the entirety of the record since the there is no like there's no empty commit when the commit is empty the commit is dropped right yes we are working on the band Branch we started a rebase of band onto Main meaning we're rewriting the history of band to include all the changes of main we effectively removed all the changes of the I commit by choosing to keep the changes from Main instead of band we
continued to rebase and get realized that the I commit was pointless because we're rewriting history anyways just remove it there's literally nothing in it right there's no I in team that's why if our if our changes had been more complicated say we kept some of the changes from I commit and overrided others then git would have kept I in the commit history why did git remove our commit because this is Mega Corp and we have a strict no commit policy uh because rebase is scary and it should be avoided at all cost because it was
a essentially empty and rebase is okay with rewriting history bada bing bada boom there's nothing to commit there's nothing there it's just making life easy right uh what if the only part of the commit had been undone during the rebase comp what if only part of the commit had been undone then the commit would have still been let's see would have still been removed no the commit would have remained in the history let's let's go on to this one okay let's clean up our branches remember during these uh during the rebase of band onto Main
we actually discarded the changes of band which actually means that band is now just identical to main anyways so yeah so we're going to switch back to Main and delete uh band right uh get check out main get Branch D band there we go all right so let's delete some branches we're going to delete uh get a branch okay we did that one and now let's go over here let's go there we go all right let's move on all right disable re well uh we it should have already been disabled this this section does need
to technically go back cuz already did a local one of those uh I here I think I don't think I deleted this I'm not sure if I even have it but here I'm going to get rid of it just in case right repeat resolution setup a common complaint about rebase is that there are times when you have to manually resolve the same conflict over and over again this is especially prevalent when you have long running feature branches and even more likely multiple feature branches that are being rebased onto Main re re re to the rescue
the get re re re functionality is a bit of a hidden feature by the way this is directly from G sem can you believe that one of the most useful features of all time is just hanging out uh here hold on uh get R re re there we go let's go get SC look at this functionality is a bit of a hidden feature wait you're telling me I didn't have to resolve it every time yikes the name sound let's see stands for reuse recorded resolution as the name implies as the name implies it allows you
to ask G to remember how you resolved a hunk conflict so that the next time it sees the same conflict G can resolve it automatically in other words if re let's see if enabled a re will remember how you resolved a conflict applies to rebasing but also merging and will automatically apply that resolution the next time you see the same conflict pretty neat right am I right all right assignment create a new Branch off of Main called faves all right good check out B faves didn't use switch suck it new commands create a file called
uh faves. MD with the following contents let's go uh jump back in here go here go here wait customers okay customers uh faves faves. MD there we go cool uh commit that with message K create a copy of faves branch called fave 2 all right here we go uh we'll go in here we're going to go here we're going to CC we're going to K uh ma faves is the uh heisen right boom boom get check out dasb faves 2 so now we have the same Branch twice okay okay the same Branch twice all right
now we're going to switch back to uh Main and create a file called faves with a different content all right here we go get check out dashb main get U Manny main oh crap I created Manny get check out main get Branch D Manny got him first try uh and then go in here and put and put that in there and get status get add this get commit dasi what is it called should be with an L take the L take the L bam all right so now we have these right here we have main
on L faves on K faves 2 on K the the changes from L and K naturally conflict run the test let's go we're going to run the test we're running the test let's go we're running it confetti out of my mind are you ready for the confetti out of my mind enable the re re feature by running the following command all right so I'm just going to like this get uh get config unset local re re re enabled cuz I have a get conf config uh list grip re re re there you go I already
have it globally true for everything because I like the setting switch to faves and rebase it on to main all right get check out uh faves get brand or get rebase main there we go so notice this we're going to do this conflict we're going to be doing this recorded pre-image for customer there we go we're getting ready we're re re reing okay so we have a conflict let's do this let's solve this conflict notice out let's see hold on accept both changes all right let's accept some changes okay e yes yes yes changed get
add this get rebase continue all right so now what are we going to do with the naming um stage and rebase leave the commit message as K all right boom got it note that git May automatically open a file on your editor in which you can edit the commit message Simply Save and close and continue when you're done you should see something like this so you should notice that we should see something like this recorded resolution recorded resolution yeah we're read out of our mind we're read out of our mind now switch to faves 2
and rebase may it on to main all right get check out faves to get rebase main now look at this we have a conflict but it's already resolved right it's already resolved because we already we already resolved this specific commit so now we don't have to resolve it again it already knows what to do it already knows what to do so now I can just I can do the exact same thing I can do the whole get uh rebase continue so R is really really nice because it's one of those things that if you do
it right it is uh fantastic uh why is re disabled by default because it can lead to confusion so if you don't know what it is it's probably dangerous to have it created what's foot comes with Riri let's say you have a change that results in a conflict but you want to resolve it differently but instead it automatically resolves it for you you could feel pretty confused right so that's why it's nice to have it as a feature you opt into because that way you don't accidentally screw it up all right let's go on merge
back in PH now we have two branches faves and faves 2os that are ahead of Main in the same way we don't actually need both faves and faves 2os so switch back to main try deleting fave 2 with lowercase D flag now actually delete it with capital D we've already we've I think I'm not sure if we've actually done that get check out main if you don't know if you go if you try to delete a branch that ends there it terminates uh your commit history it'll be like yo um You probably don't want to
do that and so you have to give them the old you have to give them the old capital D and when you give him the D it then does it then merge faves into main this should result in a fast forward merge deletes the faves Branch there we go get merge faves get Branch d uh faves boom let's go grab it paste it all right accidental commit uh you know uh how let's see how with merge uh conflicts you can commit the resolution but with rebase you have to do continue dude I've done this so
much in my life I cannot tell you how many times I've done this dude I know I'm telling you which is me telling me I cannot help this one how do you undo that dude get res dude this is the greatest thing in the universe right there this solves that problem if you ever accident you've never done it really oh my gosh when I re when I when I get when I get rebase when I when I resolve a conflict I do get ad dot it immediately I go get ad rebase or get or get
commit Dash app and I commit it and I'm like and I just hate it but if you just do a reset soft remember a soft takes the commits changes applies them to your work tree and moves your branch back once so you get all of your you get your rebase right there now I believe this has been largely fixed I believe now you can actually do a rebase uh continue even after you've committed it and it just works you just get that you get that new message instead before it used to not work I love
this one why does get reset help you if you acent commit during a rebase because you can undo the commit and continue the rebase yes exactly that's why I love it okay we're going to go over a quick bit of squashing okay every Dev team will have different standards and opinions on on how to use git some teams require all poll request to contain a single commit While others prefer to see a series of small focused commits if you join a team that prefer single commit you'll need to know how to squash your commits together
to be fair even if you don't need a single commit squashing is useful to keep your G history clean yes and it makes it easy to revert again if you have a feature that could be dangerous in production and it's spread out over 12 commits that have like 18 merge commits it is really really annoying versus just having one commit at the end score squash it easy to put in easy to pull out okay what is squashing exactly well sound let's see it's what it sounds like we take all the changes from a series of
commits and squash them into a single commit okay all of them A B C D to ax easy assignment let's get ready to squash some commits push your current changes up to your forked repo on GitHub just in case your machine goes swimming don't skip this okay here we go get push origin origin main go all right uh create a new Branch off Main called temp main get check out temp m-b let's go all right so now that we have that we do all this let's go let's go we're back in um to be completely
fair I I mean I am just absolutely I I have what someone oh get checkout DB temp main yeah there we go all right how to squash perhaps confusingly squashing is done with get rebase command it may not be intuitive but remember re base allows you to apply or reapply history this will make sense more here's the uh steps to squash the last end commits start an interactive rebase with get rebase head uh or slash or Dash ey I think they call it tack ey in the military get rebased hack I head till the end
where n is the number of commits you want to squash get will open your default editor with a list of commits change the word pick to squash or S save and close the editor the I flag stands for interactive and allows you to edit the commit history before get applies the changes head till the end is how we reference the last end commits head points to the current commit there you go does that make sense uh why does rebase squash remember rebase is all about replaying changes when we uh rebase onto a specific commit end
till the or head till the end we're telling get to replay all the changes from the current branch on top of that commit then we are using the interactive flag to squash those changes so that rebase will apply them all in a single commit assignment Mega Corp Executives do not like your last few commits as a result your manager told you to squash the last three commits J L and K into a new single commit message J redacted squashing is destructive operation which is why you've decided to make the change to Temp main before moving
it to main while on temp main squash these three don't forget to pick or squash it and edit J redacted let's go uh so I'm going to go like this get rebase or first get log so we want to go all the way to J so 1 2 3 uh get rebase I head 3 Let's Go so I always go like this there we go you'll notice right here it says it right here that you can do that s stands for squash use the commit and meld it into the previous so that means s uh
go let's see how does this go it goes this let's see this one goes into the previous and then this one I forget how exactly how these things end up but either way it ends up it ends up good I forget the exact merging order uh redacted right there we go there we go so if I go get log uh one line you can see that J is redacted and the rest are all right there perfect right but they still can change the change set so if I go- P it still has the whole change
set it just doesn't have uh what's it called it just doesn't have the individual commits all right override now that temp main is in the state you want and hopefully you verified that with Git log we need to do uh what the boss asked delete the main branch rename the 10 Branch into main ensure that t main branch is gone resubmit now obviously this is a very dangerous operations we rewriting public history we're doing it just for fun because hey why not uh but we're doing it okay so don't don't do that by the way
Branch delete main get check out um get oh don't actually do uh temp main main this is this is dangerous okay there we go we did some naughty stuff we squashed main which means that because our remote main branch on GitHub uh has commits that we removed git won't allow us to push our changes because they're totally out of sync git push has a command called Force flag which allows us to override a remote Branch with our local branch it's very dangerous but useful flag that overrides the safeguards and just says make this Branch as
same as the branch so by doing this we're actually changing that stuff and that could be obviously you would never want to do this to a main okay just so you know go ahead and force push your local main to the branch on remote main uh I know by the way you should never actually do this okay this this is this is crazy okay squashing is scary when you squash commits for example ABCD and you into a single commit you're removing history from a project so all the changes are still there but the individual markers
of each changes are gone it's one big commit now in the last few lessons we erased all the commits meaning we can't go back to the individual checkpoints anymore or you can't go back easily we can still use git plumbing and reflog to actually rehydrate everything and reput it back into it we can but we're just currently not doing that when you squash commits you lose history of the individual commits that's what happens you can still get it back it's just that it's just non-trivial right when you squash commits the content stays the same correct
the content stays the change it's just that you change the commits yeah never squash Master never squash master I put that in there so I could talk about it and why it's crazy we did some weird thing squash commits to m now let's do a common thing squash all commits on a feature Branch for a poll request if your team prefers single commit poll request we will likely be your workflow create a new Branch off Main go about your work when you're ready to get your code into main squash all your commits into a single
one push your branch to the remote One open up a poll request merge it uh once it's approved all right assignment first let's just do points one and two Mega Corp needs to add a new feature to the content management system specifically they need a script that will automatically scan for sensitive information in the repo create a new Branch add scanner off of Main all right this is where things are going to get a little bit wild here get Branch or uh check out dasb I know it's switch I can't I don't want to do
it I don't want to do it I'm too much of a lite um all right in the scripts directory there's a file called scan sh replace uh the to-do comment with this all right I can't help it okay all right in the scripts uh thing scan f8 write the script there we go we got it um all right there we go we have that one run the code from the root repo all right look at that we have oh my gosh we have so many social SEC or credit cards so many co credit cards just
flying everywhere finally now we can do social security numbers add another few lines to the script all right there we go uh run the script again to ensure it works oh did I not oh I forgot to commit oh I forgot to commit I forgot to commit hold on k um uh credits there we go wait why isn't that working oh did I did I actually delete oh crap all right there we go now we can paste this in there we go all right there we go so now I can go CC and this one
should be J right this should be L yep okay so this one will be L um this one will be uh Social Security numbers my bad my bad I accidentally did that one out of order now we should do phone numbers there we go add add one for phone numbers added it for phone numbers there we go there's some phone numbers in there CC uh and this is HJ K LM uh phone numbers there we go looking good run the script one last time make sure it works there we go all right I actually uh
I accidentally uh I accidental your commit I know happens there we go all right so we got ourselves set up for this nice next one squash series remember the full workflow we're going to be doing which we already talked about this creating your branch making your commits squashing it making the pull request let's tackle point three squash uh KLM into a single uh new commit starting with k remove L&M all right so do it again get rebase I head till the3 do these ones uh SS there we go and go into k there we go
Bam Bam Bam Bam got those two uh we are rewriting the history of our own uh Branch let's see to make it look as if we did all the work in a single Commit This is normal and fine because it's our Branch yes it's our Branch now it's okay to do right now it's okay before it wasn't okay to do and we did it on Main which we shouldn't have done it on Main but it's give me something to talk about give me a reason not to do that our Branch all right so now we're
going to do four and five uh use get push to add scanner and open a PO request all right get push origin uh add scanner there we go we're going to do that and we're going to go to back end we're going to go to GitHub the prime gen which update Mega Corp and there we go P requests new pull request add scanner let's go create pull request create it let's go looking good looking good oh my goodness how do you not have my repo name I thought you had it all right I'm just going
to copy that one and bring it back in here and go the primagen there we go and run all checks oh am I doing it oh uh to main on your mega Corp oh crap I did on I did it on your mega Corp I didn't read the instructions good I in fact did not read good instructions here I in facted terrible instructions reading there we go uh apparently I can't change uh where my remote is pointing to which is kind of weird that's fine GitHub the prime engine um mega Corp there we go so
I effed it up I effed it up apparently the UI doesn't let you change the base reading instructions are required for squares yeah losers add scanner there we go sorry the previous one didn't require me to required me to do it on a different one so it got me a little bit confused all right there we go merge the poll request remember we did all that one now let's tle pack point six merge your pull request from uh ad scanner into main you can also do so by clicking the Big Green merge request button uh
when you're done you switch back to main branch locally here's the scary part delete your local ad scanner Branch pull the latest change it from Main and your local main branch should have a now commit K yeah some people get freaked out it's okay when you have centralized merge stuff it's not a big deal hit the big green button confirm the merge get check out main get Branch Big D delete add scanner right boom get it out get uh pull oh my gosh I didn't set I didn't set that there we go get pull my
Branch wasn't pulled there we go look at that good yeah there we go we got the energy we got it all done absolutely fantastic it's all in all right wait did that mean I did it [Music] okay stash all right so now we're going on to stash are you guys ready for some stash all right you've been at Mega cor for a while three whole days and to your mother surprise you're still employed here's the workflow you've been using as a junior developer commit some let's see commit some changes to a feature branch open a
poll request from that feature Branch to Maine check out the new feature branch and and start back to the next task today however is a big day all right today is a big let's see big day let's see the customers are complaining about a critical bug and the CEO saw you first she asked you to drop everything and fix it immediately but you've got a bunch of unstaged changes that you're not ready to commit yet and you don't want to lose what do many git noobs would create a second clone of the git repo at
this point a huge mistake you're better than that that's right you are better than that uh the get stash command records the current state of your working directory and the index staging area it's kind of like your computer's copy paste clipboard it records those changes in a safe place and reverts the working directory to match the head commit the last commit on your current Branch to stash your current changes do get stash yeah and stash list to list your changes don't look at that my stashing workflow looks a little something like this I usually have
some amount of work that's in my index or my work tree and I get a request in that says hey can you please investigate this bug or hey you need to pull in the latest changes because if you pull in the latest changes the feature you're developing will have a couple extra apis that you need which means I'm going to have to take my changes create a commit pull in the new changes finish off the change I wanted to make create another commit then squash those two commits into one or I could just stash my
work tree and my index pull in the changes and then pop off my stash when I need to get back to doing what I was doing and finish the change I was trying to make now the the times that I don't do that approach the times that I don't choose stash which often I do is whenever I had to pull in a change but I'm already in several commits into a change I'm trying to make typically I try to keep my changes pretty small but every now and then you'll have like a thousand line change
and whenever I have a big change like that I try to make small commits along the way as nice checkpoints in case I screw something up so bad that I can just roll back to the last known working commit and then start again so if that happens I simply make another temporary commit rebase in my changes and then at the end of everything I'm doing I already have worked in that I'm going to squash everything down to one commit anyway so it doesn't bother me all right assignment while on Main update readme.md in the root
of megga Cort repo to do this one B bam just after updating read me uh that the CEO approached you stash the changes once you're stashed make sure that they are uh safe in your list let's see they are safe by listing now it's okay you would be able to single see a single stash list okay all right um let's go into here let's go to read me uh let's let's see let's delete that and go to this one there we go GS we have look at this look at this we have our read me
but bam we got to stash some changes so I'm going to jump in here and go uh so for those that don't know get stash all it does uh is it takes whatever you were doing and puts it into like a special area it's kind of like uh it's kind of like it it's kind of like a commit uh so if I look at get status you'll notice there's nothing there get stash list uh you'll notice that there is one right here if we go get stash list I believe it's- P you can see the
change right here right it's just like a special place to be able to put changes for a moment I never use it longterm if you use it long term you're crazy don't do that that's absolutely nutty to do right absolute nutty to do all right stash has a few options get stash pop list the pop command will by default uh apply your most recent stash ENT to your working directory and remove it from the stash list it is effectively UND does the stash command it gets you back to where you were this is called a
stack and that's important okay pop your stash change back out you should see it working get stash uh pop so it's a stack and that's really really important to know because if you push two things on top of your stash you will have your latest one on top the stash command stores your changes uh in a stack Pho data structure also I wouldn't say uh I wouldn't say Pho okay I'm last in first out I'm more of a lifo kind of person Lane again your copy editing hurts my feelings here I'm a lifo not a
pho or not a I'm a lifo not a pho yeah for sure that means that whenever you retrieve your changes from the stash you always get the most recent changes that's true bada bam uh Pho is greater than lifo W Lane false all right stash is a collection of changes that you have not committed they might be raw working directory changes or they might be stage changes both can be stash for example example make some changes to your working directory stash those changes make some more CH let's see make some more changes without stage them
stash all of that when you do that the stash entry will contain both staged and unstaged changes and both your working directory and index will be reverted to the state of your last commit it's very convenient way to pause your work and come back later git stash is a very convenient feature of git in which allows you to store your index and your work tree into a special area known as the stash and then later on to be able to pop off those changes and reapply them to your work tree /index but what is the
stash well it's a data structure that is a stack so every single time you have a change to your index SL workor tree and you want to save it for later when you call G stash it actually creates something that's like a commit and adds it to this data structure pushes it onto the stash stack any files that were not a part of your index slthe work tree will simply be ignored when you call get stash pop it's actually going to take the last thing that you added to the stash and apply it to your
current work tree /index X that means if you stash three changes a b then C if you pop something off you'll be popping off C then the next time you pop off it will be B then the final time you pop off it will be a if you're unfamiliar with a stack it's actually pretty simple think of a stack of plates if I add a plate then add a plate then add a plate if I wish to remove a plate I would never try to grab from the bottom IID just grab one from the top
then the next one then the next one Whatever order you put in is the reverse order of what you take out in other words it's a last in first out data structure you can inspect your git stash by simply executing git stash list which will show you in the order in which you pop out your stashes often I use the stash in a very one-dimensional way I have some changes that I need to pull in from Main so I'm going to stash my current changes pull them in pop off my current changes and continue on
my work I never use the stash as like a long-term storage place just because my code changes so fast that it often gets out of date super quick what is not staged unchanged uh unstaged changes to the track let's see to the tracked working directory stag changes committed changes you can't stage a commit okay you can't triple triple stamp a double stamp if you push three sets of changes into the stack let's call the first one a the next B the last one C what happens when you run get stash pop the changes from C
are applied to your working directory but the stash entry is not removed the changes from c i remember clicking this last time it got me this changes from C are applied to here working directly and the stash entry is removed let's go multiple stashes you can stash changes with a message I rarely use stash in fact I never use stash messages that I can remember I've used it like once or twice the big reason why I don't do that is whenever you're doing this this means that you actually want to come back much later which
to me just says this needs to be a branch in which you keep somewhere and then you can edit the commit if you want to you can rebase the commit uh for me stashing is a very very like temporal operation assignment restash the changes to readme with the message good marketing update the readme uh file again with the following contents right get stash uh message uh good marketing boom right and so we're going to go back here and I'm going to go delete and I'm going to have this one there we go now let's see
stash those changes with bad marketing uh get stash bad marketing there we go and now we should do a stash list get stash list you can see these two different ones right here so that means if you add a p in here you can see the difference unite Marketing sales and service in a single app try Mega Corp starter Suite today there is nothing uh to install no credit card required the only thing standing between you and more customers are you are your terrible salespeople get started today it's a pretty good that's a pretty good
one that's feels good feels good all right so there we go all right unrelated commit now that you've safely stashed your current work let's tackle the CEO's urgent matter CG uh Mega corpse APO script or shell script truly is a feet of engineering it behaves exactly as the shell borne shell language but with the word let's see but if the word shell or sh is ever mentioned in the standard out it will replace it with APO it's a feature that customers love but it's not working let's see test by running scan with the APO language
for Shell there we go we're going to grab this one there we go so you can see it right here it's all right there okay uh the grap command let's see the grab command should filter out the output to the lines that contain sh uh you should see a couple lines which means APO sh isn't doing its job uh the culprit is this line yeah yeah it should be replaced with SH not bash all right we're going to update the script we're going to update the script right all right let's update the script man customers
love just the craziest things huh uh scripts Apo there we go wait a second there it is we got the Apex okay you're right get status get add this get commit get commit L the L stands for lovely reading the primin there we go all right now that we got that apply without removing from the stash so you can actually do that I'm not really sure the purpose of this but it does exist uh you can apply without or you can you can remove from stash without applying this makes more sense Lane W Prim L
yeah I know it happened reference a specific stash so you can actually do it in one of these locations with the at sign so that means we probably we're going to have to do the one run uh get stash list see what uh see the stashes you have apply the changes from good marketing stash index without REM moving it from the stash list so we just have to do a little apply do one of these bad boys get stash list um paste that in there one there we go uh get add your changes to the
index drop good marketing stash pop the only remaining one bad marking you should notice that you have a conflict resolve it by keeping the changes from good marketing stash commit the changes M all right let's do that uh get stash drop um stash uh at one there we go get stash or get add this get stash pop wait oh whoopsies uh hold on get what happened get status did I miss what happened here uh Vim read me there we go I missed the message that said it it did the wrong thing so there we go
I'm going to remove the bad marketing one call it a get I missed the conflict message how did I miss that oh it's right there it was right there the whole time I just missant again it's that reading thing you know what I mean okay it's that reading thing that really gets me [Music] okay all right revert when reset is a sledgehammer revert is a scalpel uh revert is effectively an anti- commit it does not remove the commit like reset but instead creates a new commit that does the exact opposite of the commit being reverted
it undoes the change but keeps the full history of the change and it's undoing so it's kind of like the Spider-Man thing you know I mean grug reading for a living but grug no read yeah I know it's sometimes you feel right all right to revert a commit you need to know what commit the are the commit hash of the commit you want to revert you can do it with Git log all right and once you have it you do a little get revert hash with a committes assignment uh in your great haste of pursuit
of greatness at Mega Corp you forgot to write a white paper and get approval from the l69 distinguished staff architect for your marketing documentation change the l69 has requested you revert the change and sure you are on Main revert commit M it should prompt you to write a commit message and we're going to call it n let's do it all right so we're going to go like this uh get log one line so what do we need we need this guy right here bam get revert that one and save get log on line you can
see right here here looks like this get log um on line- P2 so look at this you can you can see that it's literally the inversion of it the starter repo for the G course 2 that one removed it this one added it back this one added this this one removed it this one added that that one removed it so it's like an inversion so that's what a revert does it literally does like an anti-matter commit to your history and then it turns it into a commit so you actually have it as a part of
your graph Oh shoot that's not right right that's not right that's not right did I mess that up I must have messed that up yeah see it says get revert M okay that's my bad uh get commit uh amend all right there we go that was my fault that was my fault still doesn't read I still I literally cannot read the get diff command shows you the difference between stuff differences between commits and the working tree Etc I frequently use it to look at changes between the current state of my code and the last commment
um I use it to look at I I primarily use it to look not at that I primar well I mean yes actually that's exactly I my current state sorry that red funny what my current changes are I rarely use it for uh staged stuff if you want to do stage you have to do dash dash staged uh show the changes between the working Tre the last commit uh you can do that you can do difference between branches you can do difference between two hashes I've tried to do this for bigger ones in bigger projects
once you get to a certain size it's like impossible diff the changes between n and M commits remember n is the version of changes and paste the full output in here get diff uh a head till one I believe is all I need to do I think I can't remember submit boom yeah there we go bro do you even diff I diff I diff okay just copy P into notepad Plus+ with the differences extension wait what why would you do that revert versus reset reset soft undoes the Comm but keeps the uh stage changes undoes
the commit and discards the changes revert creates a new commit and undoes the previous commit there you go when to reset if you're working on your own branch and you're just undoing something you've already committed say you're cleaning everything up so you can open a poll request then get reset is probably what you want however if you want to undo change that's already on the shared branch especially if it's an older change then get revert is the safer option it won't rate any history and therefore you won't step on your co-worker toes don't look at
that don't look at it when do you use reverse versus reset well they're actually quite different operations so you just need to understand them fundamentally and it'll become obvious when you use one versus the other whenever I use reset it's because I want to be able to take a commit undo that commit make some edits and recommit and in the case of get reset hard I actually just want to throw away that commit this means I'm working on my own Branch not on a branch everybody else uses I'm able to edit the history and get
it into the way I would like it to be whereas a revert is more for the public Branch what this means is that you have a problematic commit and you need to be able to remove that commit but you could never do that to a public branches it's going to break everybody so instead you make like an anti-matter commit right this commit contains changes a this one reverts changes a and this also has the added benefit that if you want to go back in time you can go back to a and actually fix the bug
and then reintroduce a along with its bug fix now I find that I revert when I'm on a larger team because often you're in this position where where somebody needs this change to go out such that a new customer feature or a new Ab test that's high priority has to get out but your changes have broken the build and we're not discovered until we released into production so we need them out right away there is no waiting there is no waiting to fix forward so therefore you simply revert your commit fix the change create a
new commit with the fixed code and all the changes back in and then next release your code can go out and hopefully it's not broken but if you find yourself reverting a lot it's likely because you have a pretty unhealthy process your cicd is not up to Snuff your tests aren't quite there your automation is no good production is the ultimate place to test but it should not be the only place you test which creates a new commit revert let's go Which rewrites history [Music] reset all right there we go cherry pick everyone loves cherry
pick this comes a time in every developer's life when you want to yink a commit from a brand but you don't want to merge or rebase because you don't want all the commits get cherry pick is another one of these very useful git operations but you infrequently need to use it cherry pick is when you want one change from a branch but you don't want the entire history of the branch you only just want say a singular commit or two commits Where cherry pick is obviously useful is when you have a branch that's called release
and then you have your main development line every now and then release gets cut and that Branch gets updated now let's pretend you've been going in their there's hundreds of commit in Maine but we discover a bug in production well we can fix the bug in Maine and then just transfer over that one in singular commit to release and then reproducti release thus fixing the bug but we don't contain all of the changes from Maine because those changes are largely untested or may they contain half-baked features that are not ready to go out quite yet
so This Is Where cherry pick Works a switch to a new Branch off of Main called ad Partners update the partners organization to be this one commit the changes with o update the same file again with P all right let's do that uh all right get Branch let's see what branches I have all right cool get uh check out dasb still not doing it still not using it Lane was just like we should use switch and I was like dude I'm all About That C about that c get check out I just didn't I can't
help it I can't help it I I just I just have to all right there we go won't sub if you don't use switch nope then don't sub I'll ban you how about that one how about that one tough guy get commit d o okay the setup we're going to do the setup my face oh than wait yes so now we got to do p all right uh Vim Partners uh dap paste let's go here get status get status get add get commit dasp on the electric fence huh little call back to Ren and Stimpy
I think I spelled fence wrong whatever that's close enough you know what we're close enough that's a little Ren and Stimpy call back okay it's been a long time since I've watched some Ren Stimpy okay close it enough all right what theme of V code is this you know exactly what theme it is can read nor write all right how to cherry pick uh first you need to clean uh clean working tree no one committed changes identify the commit you want to cherry pick typically with get log is a good one run get cherry pick
commit or commit would be better get log to grab the first uh of the two commits we just made oh that's the one we want get log there we go I'm going to grab this bad boy my oace then we're going to go in here cherry pick o on to main ensure that it let's see it worked by checking the partners one delete add Partners boom get Cherry uh pick that oh I just did it onto my own thing get uh get status it uh I didn't even change branches uh abort abort abort boom oh
my goodness I have a revert in Pro oh my goodness wait how am I how do I have a revert in progress how did I do that okay when when when did I do this all right hold on uh get log all right so I have the revert right here all right so that's already been committed so that's not a problem get uh get Branch we have our two branches I'm on Main uh let's see no Cherry pit oh I have a board am I actually calling aort oh dude I'm so stupid I didn't even
see that I was doing aort okay I am really not reading it's been a long day I don't know if you guys know this but I've been streaming for track hours nine hours okay it's been a long day all right there we go so I moved over this right here so I can go get log DP so we can see right here closed ml one of our favorite startups right can't even read the timer okay shut up shut up it's been so long I'm not good at doing this much this much stuff at a time
all right we need to delete the ad partners get uh Branch delete ad Partners there we go the man's losing I've lost it I fully lost it I've lost it I've lost it let's go first [Music] try oh yeah we're up to bisect do you like bisect you guys you guys want a BCT all right so bisect is fantastic let's do this okay let's do this get bisect is yet another get command that does sound quite intimidating to the uninitiated but once you learn how works it is actually quite simple get bisect allows you to
find a commit in which introduced a bug really fast and it does this by using a technique called binary search let's just pretend that we have a branch that has many commits on it our latest commit contains a bug and a 100 commits ago does not contain the bug how are you going to find when the bug was introduced well you could go step by step through it until you find where the bug's at but that would be tedious if it takes couple minutes per try it could take all afternoon or multiple days but since
commits are ordered by time in which they are merged we can actually pretend they are an ordered array and do a binary search across it so this is how git bisect Works let's pretend that we have a known state that is bad and a known state that is good and we have a bunch of commits in between all of this we'll call it X amounts of commits if we test the middle commit and let's pretend we found this middle commit is good we know that all of this is good in other words we've cut our
space in half we have x / 2us 1 left commits to check and if we repeat the process we can continue on finding smaller and smaller regions to go check for our commits if we find one of these are actually bad then we know that all of this direction is bad and we repeat this process until we're able to find a singular commit that is the commit in which the bug was introduced if x was a th000 it would approximately take us 10 checks to find the bug and using git bisect is really simple you
set the good commit you set the bad commit you say start and it will start doing that exact same process of cutting the known space in half asking you if this commit is good or bad if you answer good then it knows all the commits earlier are good if you answer bad it knows all the commits that are ahead are bad this can save you days of searching so we know how to fix problems in our code we can either revert the commit with a uh the bug this is more common on large teams or
fail forward by just writing a new commit that fixes the bu this is more common on small teams well it's if you have the time that's the this is the ideal in my head is to be able to always fail forward right that is my favorite uh but there's another question how do we find where the bug was introduced that's where get bisect command comes in instead of manually checking all the commits that's Big O O right Big O N I mean get bisect allows us to do a binary search which is login so that
means after like what 10,000 it's only 14 checks it's the way to go so if you don't know how to do bisect you bisect is fantastic if you're working on a slightly old code base that has thousands or hundreds of commits right all right let's see BCT isn't just for bugs you can do anything so the nice part about this is anytime you have a change you're looking for and you have a script that you can check then bi sector can be used to find where that say Improvement and performance Improvement was Ed introduced performance
uh regression was introduced anything so bisect is fantastic the B the purpose of bisect is to split the repositories into two separate repositories split the commit into two find a commit that introduced a bug or change say it that way uh a commit to find a change that was introduced there are seven effective steps to bisecting that's it there's only a quick seven now you know you know me from reading right am I right you know my skills at reading so we're about to go deep on this one okay yeah yeah all right start the
bisect with get bisect start select a good commit select a bad commit uh get will check the commits between them and find it execute uh get BCT good or bad to say the current commit is good or bad uh loop back to step four exit with this one get bisect receip or uh reset there we go assignment your boss just chewed you out because the scan a sh script should never have been added to the repo not only does she want the contents of the script erased but she wants to know when the script was
added and for you to fix it with get revert so the history of your Royal screw up is preserved considering you can't remember when you wrote the script you decided to use get bisect start BCT you know the head commit is bad so Market is bad you know the first commit a is good so mark it as a if the script content is pres uh present not just a to-do comment Mark the script as bad otherwise mark it as good repeat step four until get bisect completes it should give you the hash of the commit
all right so this should be pretty easy do you understand here right boss should have been in code riew yeah I know boss boss yapping but boss wasn't wasn't reviewing that's what I'm seeing right now people lot of yapping not a lot of looking uh all right let's see revert the commit that introduced the script with commit message P am I right am I right all right so let's find out when that happens so we're going to go like this I'm going to do the following I'm going to go get uh Buy uh um start
right so we're going to start it waiting for both good and bad commits so I'm going to go get a BCT uh bad so that just says oh did I BCT there we go I literally could not see the difference there bad so you don't actually have to provide a commit if you want to use the current one so there we go I just used the current one uh get log one line go all the way down to the bottom get uh BCT good we know is somewhere right there so now notice that it has
six rever Visions left uh to test after this roughly three steps so we can go we can go cat uh scripts scan word count line all right so there is one line so this was just the to-do right so when it has one line it is the to-do okay so that would be get bisect good we like that one this one has 10 lines so that one's bad this one's bad all right this one's so this one's also bad all right this one's good I'll explain what's happening in more detail here for a second there
we go you can see exactly where this has happened and you can even see right here K credits so all right I think this is good uh get log DP this thing you can even see right here this is where the changes were made to the uh scan script so what actually happened there it's actually not that bad you can imagine that at a that's our first commit and I forget what our uh head is right whatever commit that was head how a bisect actually works is that remember each Comm has an ordering to it
this is an ordered array therefore the ordering of course being merge order or it's going to be like say time and so that means we're going to go b c and all the way up to head that means if we check the middle element and it's bad that means this entire side is bad but if we check the middle element and it's good that means this entire side is good so since the first one was good we know that all of we know that all of this let's see hold on shoot which one is that
if we know this one was good we know that the rest of these were good right here so that means we went in the middle of this one so then when we checked here and it was bad we knew that all of these were bad so then we went into the middle right here and when we checked this one since it was bad as well we knew that all these are bad so we went and checked right here and since that one was good then either the one right after it since there's only one commit
left between these two it was able to say that this one was the bad one it's a binary search that's effectively what happened right sorry for my fairly shoddy explanation but that's all it is bisect is really simple right it's it's it's really easy you can think of this like an ordered array imagine you have an array that goes 1 2 3 4 5 6 7 8 and you wanted to find out if it has the number six well what you could do is if this is zero and this would be uh8 right the ending
it's of length eight you could do 8 minus 0 ID two which gives you four and you can check this one is this six no it's not is it greater than it is since it's greater we need to check this one okay that means we need to update our lower bound to this one so now that's going to be three 0 1 2 3 we still have eight as the length so we do it again what is 8 - 3 / 2 which is going to be what two 2 and a half two then add
it to three so we got to go to five which is going to be four five is this one it yes it is we're done say we're looking for seven then we do the exact same thing again which we'd have to go to Five 8 - 5 is 1 divide by two that or that's three divid by two that's one add it to one all right seven check here is this it yes it is good so that's all it is it's pretty easy um binary search is really really easy to do right and it's great
it's actually really really great so that's all bisect was doing was that so now that we have that we're going to go like this uh get uh BCT uh reset oh my goodness BCT I I I can't read that word get uh revert that one p there we go sounds like successive approximation well whenever you have an order you can search the space more efficiently given an input if you don't have an order you cannot search space efficiently that's why things like uh that's why eventually you just have to do a linear search through everything
if you have no order linear is quote unquote slow linear is slow but it's not as bad as like quadratic or uh even more that was annoying now imagine if testing wasn't as simple as just looking at a file manually running an automated test can take a long time as compiling uh a gasp J Java Enterprise project absolutely uh for the man get BCT you can do bisect run now this is cool okay bisect run allows you to be able to do that process we just did but in an automated way now this is very
important because sometimes you have to sit there for 30 minutes for something to tell you if it's correct or not so it's much nicer to be able to just have this thing run and then you go play I don't know play game basketball whatever you do I'm not sure what you do okay so there we go there we go let's create a new script in scripts called BCT sh with this contents so that means if we find scanning in the scan we exit with a bad exit code if we don't find it we exit with
a good exit code in other words uh BCT when you run it uses the exit code to determine if it's a good or bad build so let's go in here Vim this thing up go into scripts go BCT Dosh go in here do that make it executable uh I prefer to hit a oh yeah I guess I don't need to do I don't need to do a shebang there we go and now I need I can go into here and do the exact same thing and I can run this script now so I can go
like this we already chimed it we can do a bisc start and go get uh get BCT uh start get BCT bad get BCT good that there we go so we have our head to our tail and now we're going to run through and do this thing even though technically we're doing a bad with our current one you know there's a little bit of something weird here so I can go cuz we reverted it so technically our head break our whole ordering but don't worry about it we we can skip that get bisect run um
scripts bisect and I believe we don't need to yeah there we go we don't need to provide any arguments so when we do this one there we go it found it is able to run that script super fast and find it immediately there we go and now we know where the problem was see bisect is pretty cool what does automating bisect require uh an automated test that can programmatically inform git if the current commit is good or bad that's pretty much it there we go all right work trees uh we've been saying work tree all
throughout this course but I have been misusing it I am sorry it's not technically what we're on is not called it's not work tree precisely uh it's the main work tree which is more precise because you can have more than one working tree what is a work tree a work tree or a working tree or working directory is just the directory on your file system where the code you are tracking with Git lives usually it's just the root of your git repo where the dogit repo is it contains tracked files untracked files modified files right
everyone know everyone can fundamentally understand what a work tree is your main working tree just makes sense the work tree command get as a work tree command that allows you to work the work trees the first subcommand we'll worry about is simple get work tree list it lists all the working trees you created all right so let's see what working trees we've created you'll notice there's only one working tree right yeah which is my current my current work tree right linked work trees uh we've talked about stash temporary storage for changes branches parallel lines of
development clone copying an entire repo work trees accomplish a similar goal allow you to work on different changes without losing work but are particularly useful when you want to switch back and forth between two change sets without having to run a bunch of git commands not branches or stash you want to keep a light foot print on your machine that's still connected to the main repo not a clone so this work trees effectively allow you not to have to clone out a repo for a second version of it there's some like requirements there's some rules
I think I go over the exact rules in here the main work tree contains a git directory that's important with the entire state of the repo heavy lots of data in there to get a new main working tree requires get clone or get a knit uh a link work tree contains a git file with a path to the main working tree it's effectively as light you can think of it as almost as light as a branch it's just like a little bit heavier than a branch U let's see uh can be complicated to work with
when it comes to end files and secrets this is where things kind of usually go off the rails for work trees is work trees can be a pain in the butt when you have uh say node modules node modules can be really annoying so we can create a new work tree like this we do this uh whenever you do a path on an ad if you do not include a branch name it takes the the uh first baster of the path and uses that as the branch name and it'll actually create it so we can
create a linked working tree uh as a sister directory to your main working tree called alra Corp uh use the default Ultra Corp Branch so watch this so I can go uh oopsies uh get uh get a bict uh reset forgot to do that get a work uh tree ad what is it it's path which is going to be let's call it Ultra Corp there we go so prepared to new work tree it's called alra Corp so if I go here back out and go Ultra Corp you'll notice that Ultra Corp is on Branch alra
Corp because that was the Bas that was the first base dur of the path that I did so if I would have done like Ultra Corp SL fuar then the branch would have been bar if that makes sense and so now if I go like this cat get you'll notice it's literally just a pointer to where it needs to be right so there it is primagen personal Mega Cort get work trees Ultra Corp so it's saying where it's located at pretty cool right I've been programming for 12 years and I like to think of get
as magic under the hood it's really it's it's it's shockingly it's not the most complicated piece of software I'm sure the actual operations for like creating and deleting files and stuff like that is complicated but everything else is uh like how it works is actually not like the most oh my gosh how could this possibly be right all right no duplicate branches linked work trees uh behave like normal get repos you can create branches switch branches delete branches create tags Etc but there is one thing you cannot do you cannot work on the branch that
is currently checked out by another tree branch navigate to ultra Corp attempt to switch to main so when I try to switch out main it says already used right makes sense right yeah tracking so how does your main tree uh main working tree know about your linked working tree well the reference is stored in G work trees directory list the contents of this directory so if we go like this if we go to here and go uh ls- La get work trees this is a new one you'll notice that Ultra Corp is right here so
if I go in here you'll notice that it has effectively the entirety of everything you need to know about it where its head is pointing it's like a mini little it's like a little mini git experiences going on right here here and even has a g dur and you'll notice that the G dur if we look at it will actually be like the inversion of the other one whoopsies there we go oh my goodness how did I get that there we go it's the path to where we're going so that's how it know it exists
that's why when I go work tree list it's able to actually find this if I were to delete Ultra Corp it' actually say like dead or prune or something like that removed I forget what it says but it says something how does the work tree keep track of it the main working let's see the work Tre directory contains references to them yep Mega corpse IT staff manually logs it in Juro their project manager software actual magic which one is it all right when you make a change in a linked work tree the change is automatically
reflected in the main work tree it makes sense the linked work tree doesn't have a g directory so it's not a separate repository it's just a different view of the same repository you can almost think of a linked work tree as just another branch in the same repo but with its own space on the file system run get branch on your main work tree uh and answer the question so if I click this get Branch look at that you can even see the little plus sign right there that's because it's being checked out in a
work tree it's kind of fun thing uh how can you tell if a branch has checked out uh in a different work tree uh the branch will have no prefix that has a plus prefix let's go plus prefix let's go deleting work trees you may never need the stash again this is the nice part about working with work trees is you don't actually ever need the stash ever again you can have two work trees that are always you know you can switch between them you can always check out a new one every time you work
on a branch I had somebody at my old uh job tell me that stashing or switching branches is an anti- pattern you should just always work tree um anyways however at some point you need to clean up your work trees the simplest way was to remove the subcommand you can do a remove but you can also do something cooler which I actually prefer you can just delete the directory watch this one uh let's see hold on does it say that remove alra Corp cool get uh rmrf backback alra Corp there we go so if I
go get work tree list again you can see this right here see prunable I knew it said something I couldn't remember the word it said but now that means if I go get work tree prune it's able to tell what to prune because remember when we did this when we CED the gter ultra Corp had a directory so when it goes and it goes here it cats out this thing it stats that file when that file doesn't exist then it knows that it doesn't work that this thing has been detached what about npn modules you
have that I mean you can copy you can create a script right I just I talked about that the whole environment part of work trees can be difficult right there we go bam I always had like two or three working trees and I would actually just switch between them so whenever I needed to do something I could actually just grab that and change it all right tags uh we're going to wrap up this course with an easy one tags tags again I showed this at the very beginning of the course tags has the craziest user
manual but it's so simple to list all the tags you can just do get tag so get tag I have no tags very very easy tag is just an immutable pointer to a commit very very nice we can create a tag by just doing this tag a give it a tag name give it a message all of that all right create a tag on the latest commit p with the name candidate and a descriptive message all right get tag uh a see so we can go get tag- a if you want a name so the
name can be candidate like that right and then you can do a message message such candid candidate boom get tag look at that beauty right there you can you can also if I'm not mistaken you can also create a uh tag without having to do this right there you go you don't have to use a a it's like the default first parameter there we go now tags remember you cannot edit a tag so when I check out a tag get check out tag let's you get check out candidate I go into a detached head State
like you can't make edits to a tag tags are immutable pointers it's very important to remember that and also one last thing get log one line you can also see uh tags when you have decorations which is nice why would one use a tag oh very very simple let's go like this let's go to uh GitHub uh react let's just go check out the react Library let's check out what tags they have tags do those look familiar if you've kept track at all react server components exist in 18 right people typically use tags to point
to versions that are released in public so this is like a very normal Behavior Uh that you should see tags for they're usually some sort of release uh now you can do stuff with sver this is typically how people do this with just sver it's kind of weird to just name tags any old thing we're developers we like structure sameness and sometimes even bike shedding I love bike Shing sver semantic versioning is a name and Convention by the way I've been bit so hard by sver because of this one right here minor sometimes it isn't
a safe feature if people change default parameters just so you know default parameters don't technically break major versioning of sver and can screw you just so you know just in case you're wondering note V isn't actually a part of the sver correct major this means a change to the API in which will break compiling code minor means a an additive change to the API that won't break a code patch means no change to the API at all there you go um that's the easiest way to say it uh the sort let's see to sort them
from highest to lowest uh you first compare the major versions then a major minor versions then finally patch versions for example major version 2 is always greater than major version one regardless of the minor version absolutely if I'm using some code that's on V1 124 and I see a new version 224 is available should I expect to be able to safely upgrade without making any changes to use it no major versions are not backwards compatible or typically are not major are not backwards compatible good thing to know you know what I mean good thing to
know what's the highest version 422 422 let's go I'm so good at this I'm so good at this conventional tags um tags are used for all sorts of reasons but sometimes they're used to uh to denote releases in that case tags follow the sver are common right here so tags this is very normal right fun fact pretty much anywhere you can use a commit hash you can use a tag uh name when working with Git right it's a commit let's see assignment add another tag to this let's see to the same latest commit right commits
going have multiple tags which we already did and then there we go boom uh get tag V 1.0.0 that'd be like oopsies that'd be like a normal one get push uh tags there we go push them all up let's go got it tags okay guys stop making fun of my tags there we go we're done I just did two git courses thank you very very much I hope you enjoyed this presentation of boot dodev GS course in which I helped create quite a bit the name is the primagen boot. deprime use it