Transcripts
1. Git & Github 201: Course introduction: Welcome to Git and GitHub 201 intermediate get workflow. In this class, I'll be showing you modern ways to work with other developers. How do you contribute to other people's code? And overall, just the general modern workflow that every programmer and developer needs to know. In order to work with a team will touch on GitHub issues, pull requests, forks, justs, get aliases and much more. And get and get hub to a one we're focused entirely on the modern development workflow is extremely important to know what you're doing with Git when you start to work with a team? I'm Caleb Italian and I've been using Git and GitHub since 2013 and today I'm going to be teaching you intermediate Git and GitHub. Support for Windows, Mac and Linux is included. Welcome to my class on Git and GitHub, and I hope to see you inside.
2. Setting up a project: Let's go ahead and get a project setup. So you are going to need a repo of your own for me, I'm just going to use github.com slash Caleb Talia slash git dash essentials. And what I'm going to do is I'm just going to clone this down into my computer. So I go git clone and then that SSH URL. Or you can use the HTTPS URL if you don't have an SSH key on GitHub yet, you probably don't if you're just taking this course for the first time. And that's okay. If you don't have an SSH key on GitHub, you can always use the HTTPS URL, but remember, use your own repo. Don't use my repo. Not yet anyways, we'll get to that at some point. But make sure you use your own repo. So you might need to create one from scratch if you don't have a rainbow already. And that's something we covered pretty in-depth in Git and GitHub 101. Next, let's cd into that folder and let's open this up. In VS Code.
3. Seeing previous commits: All right, how do we check out previous commits? What does fall? I, let's go ahead and use the terminal in VS code. And I can do git status. And you do get logged dash, dash one line and shows me my git log. We have tags and stuff in here. This is just a repo that is from another get course of mine. And let's say we want to go back in time and we want to see what happened exactly here. When we said updated, read me what happened. Let's go ahead and open up this. Read me right now. And let's see what we have in here. We've got all sorts of stuff, contributing all sorts of good stuff. Let's say we wanted to go back to this particular point in time. So get log dash, dash one line, and let's just update that Ramya. And let's go back to this particular point that whenever this was, we don't know when that was. So what I wanna do is I want to copy this commit, hash, this E19 519 F. And I wanna type git checkout and then just paste that hash in there. And you can see that some of my stuff has changed on the left there. Let's go ahead and do git log dash, dash one line. And you're gonna see that head is now at updated read me and this read me. There wasn't very much in it at that point in time. So we've now actually changed where our code is, not our code aware our Git is pointing to. And so let's say this was exactly two months ago. We just went back in time, two months. And we can see exactly all the code that was, that existed from this commit up until this point in time. Now here's the thing is whenever you go back in time with git checkout, you always have to make sure that you end up going back to your main or master branch. And so if I do git branch, you can see that head is detached at E19 5-1 nine F. And you don't want to be detached for too long. And you especially don't want to be working in detached mode. Really good for looking around. It's really good for looking around. But it's not that great for actually doing work. Actually, it's going to cause you a lot of problems if you try to work and then make a commit at this point in time. So what we need to do is we need to go back to our branch called master. Or if you're using a newer version of Git for GitHub, it's often called main. So you do git checkout master git checkout main. One of the two really depends on how old your repository is. And so all we had to do there was get checkout and then some sort of hash. And we just took the first seven or eight characters of a hash. So we could do git log dash, dash, one line. And let's go ahead and grab sample rebase. But we could do git checkout and then whatever that hashes get logged, dash, dash one line. You can see my files changed on the left there and head is now at sample rebase. And if I do git branch, I'm in detached mode. So git checkout, master. Git branch shows me I'm back on an actual branch. You always want to be working on an actual branch.
4. What are issues?: All right. Let's talk about what issues are. So issues is when you go into Git Hub or metlab or bitbucket, there's usually some sort of tab that says Issues. And an issue is used for filing a lot of different things. Possibly a bug would be a good first way to open an issue. But really it's a way to communicate with the maintainers of a project about what needs to happen or what should happen. And so an issue is, for instance, let's say we had a typo somewhere. I don't think we do, but let's say we had a typo somewhere in here. What we could do is we could open up an issue and we can say new issue and change typo in your readme, IMD. And let's just say this is a sample issue. Now, this takes markdown. Markdown is supported. So if you want to, you can go ahead and learn some markdown title. This is a block quote. And this is a sample issue with a link to HTTPS. And then let's just go to my website Caleb dot IO preview title. This is a blockquote, and this is a link to Caleb dot io. And so I can submit this new issue. And you can see that issues went from five to six up here. And so let's click back on issues and there's a new one in year. Now an issue is literally just text. It's not code. There's no code associated with it. It's just text ends. So you can have a whole conversation in here. Near could be someone stating that there's a bug and there could be a conversation in here about, oh, it's not actually a bug, it's purposely designed that way or yes, maybe it is a bug. How should we maybe go about solving this? In this issue, you can have assignee, so I'm gonna assign myself to this issue. And so that basically means I'm the owner of this issue. There are different labels. You can add an a. So for instance, you could say that there's a bug. You get add documentation because it's the Read Me that's we're assuming has a table. It actually doesn't not as far as I know anyways. And let's say it's a good first issue and help wanted. And so that adds all those labels in their projects. If we have a project, we can add a project in their milestones. Same thing, this is for more lake Agile project management. We're not gonna get into that right now. Linked poll requests. We can link a pull request if we wanted to. But we don't currently have a Pull Request associated with this yet. We have other pull requests for sure. But we don't have a pull request associated specifically with this issue. And so again, the idea here is that when someone hops on a repository, they can go over to the issues. And they can see that there's an issue of some kind and they're, now what's really nice is if you ever run into a coding problem in your issues, you could just type in what the problem is. So let's say I had a typo in a Python package and it was preventing it from working with Django. I could just click into it and I could read through it and maybe someone else has already experienced that same issue and has a solution. That's the power of an issue. Now, an issue usually is going to be associated with a pull request. So at some point in time we're going to open up a pull request and it's going to be tagged it's going to tag this particular issue, issue number 36. Issue number 36.
5. What are branches?: What are branches? So branches, while everything in Git is really a branch, so even on master or main, it's still a branch. It just happens to be the main one that we use. A branch is basically a copy, a full-blown carbon copy of all of your code from your master branch or your main branch. And it's just a couple of changes in it. And so what we can do is let's not open that. It's open this. And let's create a new branch. So first of all, let's do git branch. Make sure we're on master. And then we can do git checkout, dash b, and then our new branch name. So 20-20, one new branch name. And if I do git branch again, new branch name. Now let's go ahead and add a new file in here. And let's just close this. Read Me, I don't want to save that new file.txt. And actually let's call it something better. Let's call it new file from 2021 branch. And let's just say this is a new file from the 20-20 one branch. Now we did git checkout dash b. So what that does is it creates a new branch for us and it checked it out. And so when we do git branch, we're no longer on master where on this new branch, GitHub currently doesn't know about this branch. Those what we need to do is get status. Git add our new file from 2021 branch. You notice that I used quotations around that just to encapsulate those spaces and they're just a capture those spaces. Get status, git, commit, new branch, comment, new branch, commit, not comment. And then I want to do git push origin and then whatever this branch is called, so 2021, I hit Tab for auto completion. And what we're going to see as soon as this is done is a I can create a pull request if I wanted to get hub is now letting me do that. But more importantly, if I go in here, I can click view all branches. And there's a new branch and you're called 2021 new branch name. And so we can actually go ahead and see this entire branch. And in this branch we have new file from 2021 branch 2.txt in here. And if you look at our URL, we're in github.com slash the username slash the repo name, blob, then the branch. Oh, what did I do there? And then the branch, and then the file name. Whereas if I go back to the original source code here, the original source code and I changed my branch back to Master or main. It depends on how old your repository is. You're gonna see that that file doesn't exist in here. And so it only exists in a branch. And so the nice thing about a branch is you don't have to touch your master or your main source of code. We can do is you can create a new branch with git checkout dash b and then your branch name, so dash be branch name. And that's going to create a new branch and switch that branch for you. And then you can do all sorts of work in there. And at some point in time you can then ask Git or GitHub to open a poll request to merge in your new branch into your master work, which is what we're going to do in the next lesson. But before we do that, there's one thing we need to do. One more thing we need to do. And git branch, we need to be able to get back to master. So if we ever wanted to get back to Master, we git checkout master. And you can see this file is actually deleted and watch when I do git checkout 20-20, one new branch name on the left. That new file is going to show up. And boom, it exists only in this branch, but it does not exist in Master's of a do git checkout master it's not going to exist just like that. So branches a carbon copy of your basically your master work. And you can do whatever you want to it without affecting the main source code, which is really good when you're working with multiple people. Next up, let's talk about pull requests.
6. What are pull requests?: Alright, let's talk about pull requests. So a pull request is basically a way for you to ask the maintainer of a repository to merge in some of your code into their work. And so by doing that, you would become a contributor. And the idea here is that you simply have, for instance, a pull request or a PR for short. And then you have different commits in here. So a pull request could have multiple commits, usually comes from a different branch or another repository. This one's coming from another repository. It's been forked, we'll talk about in the future. And the branches master. And this person wants to merge their work into my master branch. And so I can see what they did here. I can see what files they changed. So it says not an empty file, dot AMD. This is not an empty file, this is not an empty file. And they said D Kravitz Cy5 replaced the lorem ipsum that used to be here with a message for the exercise at the end of lecture 33 for the get Essentials course, which is not this one, this is Git and GitHub 201. And so the idea here is that I can then review these changes and I can say, yes, this was good. I can improve these changes. And that doesn't actually do anything yet that just approved it. And then what I could do is I can mergers, pull requests, or I can squash and merge or rebase emerge. Typically we just create them. We merge the pull requests. We do a normal merchants that have a rebase. And all I have to do is press this button and it's going to go into my master branch. Now I don't want to do that yet because I want my master branch to be a little cleaner. Not that there's anything wrong with this pull request whatsoever. In fact, this is a nice clean pull request. What else can we talk about? Npr's a pull request. There's also a comment so you can open up a new poll request. For instance, let's go ahead and open up a new poll request. That's not click that button. That button was kinda cheating. Compare, I'm gonna compare my 20-20 one new branch name that's from the last lesson. And I want to put it into master. And you can see that there's one commit in here, and there's only one file that's being changed. So I can go ahead and create this pull request and new branch commit. Let's say this is a new PR test. Just testing a PR to match the issue. Issue number 36, and I just do number sign 36 and that creates a link and a nice little pop-up there. And so I can go ahead and I can create this pull request or I can add a reviewer. Let's can we add anyone in there? No, because I'm the owner of this repository so I can't add myself as a reviewer assignee, I could set myself labels. Let's say there's bug duplicate, help wanted. We could add Project Milestone, end a linked issue. Let's go ahead and create this new poll request. And so all this is going to do is open up a brand new poll requests, which we can see up here. It went from 25 to 26. And this is a new poll requests. And then someone could come in here, they can review it, they can improve it, and you can't approve your own pull requests though. And that's just for basically is for security. And so if I write some code, I want someone else to be able to review it to make sure that I don't have any flaws in my logic. And then I can merge this pull request end by hitting this button, which I'm not going to do because I want to keep this repo nice and clean, but that's all I have to do and it goes into my master branch. Now, typically we create a pull request using a new branch. So I can't create a pull request from master going into master because if I do git push origin master, it's just going to update my master branch. So I need to git push origin 2021 new branch name. And that's going to create a new branch for me. And that allows me to create this new poll request. Keep this in mind because down the road I'm going to want you to not only create a copy of I guess, this repository, but I'm gonna want you to create a pull request to put some code into this repository as well. We'll talk about that down the road. You don't have to worry about doing that right now though.
7. What is forking?: Okay, let's talk about forking. So forking, and you can see over here this 37 forks on this repository right now forked by all of these people. And what forking does is it will take my entire project here and it will copy it line by line into your account. And so let's go ahead and coding for everybody. We're gonna go to github.com slash coding for everybody. And let's take the seven days of WAG towel. And let's see. Let's make sure I don't already have this fort. No, neither of those are me. So what I can do, so I'm gonna go back and I'm going to click this fork button and I can this into any other organization or my own personal account. I'm going to select my own personal account. And so this is just going to take a quick second and this is gonna fork it over. And so you can see up here, it's now in my account there, seven days of wait till forked from coding for everybody slash seven days of white towel. And so what I can do is I can now clone this onto my computer. And I can actually modify all this code. Anyway, I like, I wouldn't be able to do that with anybody else's code if you had a repository in your account, I can't clone your eye, can't clone your project, make changes and push it back up because it's not in my GitHub account. But what I can do is fork it. So there's a copy of it in my GitHub account, then I can clone it down. And I can make all the changes I want to it. So let's do this. Let's cd up a directory, And let's do git clone. And I'm gonna paste that Lincoln their CD, seven days of pigtail, ls dash LA, or if you're on Windows DIR. And let's go ahead and open this up in VS Code. And what I'm gonna do is I'm gonna open up the terminal in here too, so I don't have to flip between two different programs. And what I wanna do here is git branch. And this is a very modern workflow that we are going to be working with here. So I'm currently on Master. If I do git remote, I think it's capital VI, git remote, lowercase v. There we go. Let's try that once more. Git remote lowercase v, the origin is pointing at Git Hub.com slash Caleb telling slash seven days of wagged l dot gets, even though this is forked from coding for everybody, I have a copy of this from my personal account on my computer now. And so let's go ahead and create a new branch, git checkout dash b, new branch demo. So git branch is to make sure I'm on that branch. And let's go ahead and let's just overwrite the readme. Overwritten by Caleb hacks or so. Now that I'm on this different branch, what I can do is I can say get status, git diff, read me and this is gonna show me that I deleted all of this stuff and go all the way down, just hitting the down arrow. And I added one line overwritten by Caleb, the hacks or git status. Git add, read me. Git status once more, git commit. And let's commit this to our branch called new branch demo. Hacks, ord as git push origin, new branch demo. Now let's go ahead and take a look at what this looks like. So if I go back here and just quickly refresh, I'm on slash Caleb, Italian slash, seven days of WAG towel on GitHub. If I go in here, I can see new branch demo. If I go to where this was forked from the original repository, the coding for everybody slash seven days of WAG tell that branch doesn't exist. It only exists my personal account. And so what I can do now is I can open up a poll request from my forked version here. So let's go ahead and compare and pull request. And so it looks a little bit different this time. What I can say is the base repository, the one that I want to merge code into is going to be this repository or any other fork of that repository. I'm going to select the original one. Which branch do I want to select? Just the master branch. It's the only branch that's in there. My head repository is going to be my account slash, my repo. Where, where do I want to merge into or emerge from rather. So I did all my working Caleb telling slash 78s of WAG tell. And I want to merge in my new branch demo into seven days of WAG. Tell the coding for everybody one, not my own, but the coding for everybody one. And so let's go ahead and first of all, it's going to pull requests and we're gonna see that there are no poll requests in there. Let's go ahead and create a pull request. And Doo-doo-doo-doo, we'll just refresh and we can see that there is a pull request in there from one organization or one individual to another organization. And I can go in here, click it. See what changed. And you know what? I don't like that. So what I'm going to do, a pull request, there's kinda prove their own pull request. That's that's too bad. I was hoping that we could get away with that because one isn't an organization called coating for everybody in the other one is a personal account. But that's not going to work. What I can do though, is I can either merge this in which I don't want to do, or I can close this poll request. I can also assign reviewers, assigned labels, all sorts of stuff. I'm gonna go ahead and just close this poll request. And it says close with unmatched commits. And what I can do now is I can delete this branch. And so I'm gonna go ahead and delete that branch. And if I go back to my, my version of this particular repo, my forked version. My branch was deleted. I just had to refresh the page there just to make sure that that work properly.
8. Deleting a repo: Okay, so I have this forked repository here and I want to delete it. So I'm just gonna go into my settings, scroll all the way down, and go delete this repository. And it's gonna make you basically copy and paste this or type it out by hand using a copy and paste that in there. And that's just going to confirm that I'm going to delete it from Caleb telling slash seventies of wait till I not the coding for everybody organizations slash seven days of white gal. So there's just confirms that you're deleting the right repository and other RAM1. And so let's click, I understand the consequences. Delete this repository. And repository deleted Simple. As that.
9. What are gists?: Alright, let's talk about gists. So what is a just? A just is a little piece of code or a few files that you can share with someone. And so let's go and click this little plus up here and say new just. And this is going to bring us to just a github.com and we can add a description. And it's a lot like a repository, but a lot smaller. It's a lot more Mini. And the idea is it's just code that you want to share and maybe embed on a website. And so let's type my first just, and this is really good for sharing large chunks of code with people. Especially if you're talking with coworkers on Slack or something. You can always just write, adjust. You can copy and paste a bunch of your code in here and then you can just send them the link. And so I've just spamming them all sorts of text on slack. So let's go. Hello, world dot py. That's what we're going to call this helloworld dot pi. And this is simply going to be a Python file. It says print, hello world with a heart. I'm going to create a either secret just or a public just. I'm gonna make sure that this is public. There is a difference though. So when we create a secret, just Secret jurists are hidden by search engines, but visible to anyone that you give the URL to. And a public just is a public just while it's available to everybody. So yeah, maybe let's go ahead and make this a secret just because this is not a valuable thing, that I don't really want to contribute this to the whole world. We can make that a secret, just we can add a second file in here, or we could delete that file. We have to have a minimum of one file. We can dictate the number of spaces if there's going to be used spaces or tabs, indenting size. If we're going to wrap or have soft wrapping or no rapping or soft wrapping. And let's go ahead and just create this secret just, and so the idea here is that I now have this link and I can copy and paste this link to you. And it's just a long hash. It's nothing fancy. And doesn't have a slug or anything. And I can just copy that, paste that link to you. And you can see this code and then you can either embed it in your website or you can download this entire thing as a zip. Now what's cool about this is it also comes with revisions, so it has basically get power behind it. So let's go ahead and edit this once more. Hello world. And let's do print. This is a second revision. Update secret just and we have two revisions in here. We have the first one and we have the second one. And so now we have the power of get behind it as well. And again, at any point in time, you can just embed that code. You can save it to your computer if you want to use the GitHub program. I don't personally use the GitHub program itself. Or you can download the zip, you could delete it, you could unsubscribe. You can have people store it as well. And so there's a lot of power behind this. And this is really, really nice if you don't want to create like a full repository, but you have like let's say just five files that you want to share with someone. This is a really good way of doing that.
10. Git aliases: Alright, let's talk about get aliases. So I have this get alias called get algae and my friend Cody sent this to me and I'm not sure where he got it from, but this is a beautiful way of seeing your git log. So we've been doing get logged dash, dash, one line. And okay, so you know, it's not bad because there's only three commits in here. But what if I did get LG? This looks a little bit nicer, a little more color, a little bit spaced out. What, what happens if I do this? Get LG in here, and does that look better? Not, Not Too Much better. Or I can open this up in my own terminal and change the sizing of it pretty easily and do get LG and this looks a lot better. And so what I can see here is that totally an author on Friday, November 13th, seven days of white-tailed source code. November 25th, he updated the ReadMe on January 14th. There's a new branch where my local Head is currently sitting on gets. So my my Git is pointing to this particular branch called new branch demo. And the commit is just called hacks 4D. We've got commit IDs down the left. And we have all this nice stuff and this all comes with good LG. Now if you type git LG Right now it's simply not going to work for you. You need an alias. And so a nice way to work with this is if I just go back here, because this is a little bit bigger, a little easier to work with while I'm recording, at least is I can type vim or nano, or maybe even code. Let's try code tilde slash dot git config. And yet that opened it up and VS Code for me. And what I have here is my entire git config. This is my personal one. So my user, Remember in get one-to-one, when we were like, What did we type? Git dash, dash, config something along those lines. User dot name and user.email. That's what we sat here. User name, user email. I also have core and stuff in here. I have a couple of different aliases because I, I check out a lot of things I type get C0 when I'm not recording videos. In order to get that get LG command. I have an alias in here. And it says L G is equal to log all of this stuff. So if I just copy that, and let's move this back up, get, and then I just paste all of that in there. It gives me that nice GET LG command again. But that's impossible to remember and impossible to type. So what we do is we throw this into an alias inside of our dot git config. And that git config again once more comes from root dot git config. I have a few other goodies in here that you might also want to steal. So rebase auto stashes equal to true. Pull rebase is equal to true. So always pull GPG program is going to be GPG to color differing. I have all the stuff in here. What I'm going to do is I'm going to paste my my entire git config into a file that you can download. So look for it in your project files or look for it in the lesson files. But yeah, all there is to really creating a get alias is open up your git config. You type alias between two hard brackets, the alias name, so get LG, You don't type git, just LG is equal to and then whatever that command is. So for instance, get C0 is the same as git checkout for me.
11. Your project: Okay, let's talk about your project. What I would like you to do is go to GitHub.com slash Caleb Colleen slash git dash essentials. And this is from a different GET course, but this is still very, very applicable. What I would like you to do is a star this repo, and be forked repo into your account. Once that's forked over to your account, What I want you to do is then clone it down to your computer from your account, not this particular one. This one's not going to work for you. Well, cloning will work, but you're not going to be able to push to it. So you're gonna want to clone from your account. So it should be github.com slash, your username slash get essentialism. You want to clone that. Then I want you to create a new branch and to create a new branch. Remember, we do git checkout, dash b, new branch name. Then I want you to add a file, create a brand new file that doesn't exist in here yet. Create a brand new file and push it up to your new branch. Once you push it up to your new branch, you should see GitHub is going to prompt you to open up a poll requests. But if it doesn't, you can always go into pull requests. And you can create a new poll request. Let's go, let's go from that one. And you're going to want to select your branch, your new branch, and you want to put it into master. So it's gonna look a little bit different from this, but we saw it in a couple of, we started a video a couple of lessons ago. So you just want to make sure that you point your repository and your branch to my repository and the master branch, go ahead and create a new poll requests. And remember at any point in time when you're creating a pull request, you can always close your own Pull Requests. So if you think you messed up, you could always just close that pull request. You can always edit your pull request. Make sure you add a little bit of text in there. And make sure that the files changed is that there's actually something in there. And last but not least, take a screenshot of your pull request and share it down below, share it with the rest of the class. I would love to see that you are actually opening a pull request here. And the whole idea is that you're going to be forking my repo. And then once you are done forking that repo, you're going to make a change, push it up to your account, and open up a poll request to ask me to bring in the changes from your version of my code. And that is the modern workflow way using pull requests. Go ahead and give that a shot and when you are done, don't forget to share your code and I'm looking forward to seeing what you have built and how your journey is coming along in the world of Git.