 In a previous video, I talked about using git with Godot and how you really don't have to do much, but it's important to use git and git is really valuable. I want to make a video that's a follow-up to that, that is actually talking through and showing the git commands and how to work with it, how to set up a repository on GitHub, and we'll walk through adding some functionality in a Godot game to give you a sense of how I commit and how often I do and what I put in those commits. So we'll go to Godot and we'll make a new project. I put my new projects in my workspace, game dev, then I have one for screencasts and we'll call this Godot git and I'm going to call the project Godot git and we'll say create folder, create, we'll do that. That's fine. We'll do compatibility. You want to have git be the version control metadata, create and edit. So this creates our new Godot project. I'm going to start by showing this all off in the terminal because I use the terminal with git and the commands in the terminal will mirror whatever GUI you're using. So if you're using GitHub for desktop or source tree or IDE integration or Godot plugin, the commands should all be the same, the verbs that are used should be the same. And I think the command line is the most consistent. So it's not that I'm teaching a certain GUI, I'm teaching the commands. I think that's helpful. So what I do is right when I start a project, well, I got to go to the directory and you got to install git. If you're on Linux, use your package manager or homebrew if you're on Mac or Windows, there's a downloader. I don't know much about Windows so I won't say anything more. I'm not your Windows person. I'm a certified Windows idiot. So if we're in our project folder, which we are now, let me bump up this text a bit. You'll see git status is the main command it tells you which files have changed, which files you have staged to be committed, et cetera. We'll get into what those all mean soon. But you'll see fatal, not a git repository. So what we need to do is initialize a git repository. That command is git init, initialize an empty git repository in our current directory. Now if we run git status, we'll see there are no commits and there are a bunch of untracked files. And Godot created the git attributes and Godot created the git ignore and we have, you know, already our icon files from Godot and the Godot project. And if we cat the project Godot, the project Godot, you'll see the settings. And that's like the beauty of Godot is it's using plain text files for the project settings for the SVG import, right? If we look at icon import, it's all just a bunch of plain text. And that's what we want, right? That's really friendly to work with. And this video is going to really focus on if you're just a solo developer. So if you're working with teammates, there's other ways of working. But as a solo developer, you can keep it pretty simple and there's just a few commands you need to know. And the benefits you get here is you get a backup of your game code, you get a log of the work you've done, and you can easily go back to previous, you know, versions of your game, states of your game's code to try to figure out bugs or debug things. It's just really helpful. And also I find it helps to have a timing, you know, of when you were working on things. Just from a, like, analysis perspective. So anyways, we'll get status again. We have nothing there. We have no commits yet because it's an empty Git repository. You create commits. Commits are atomical changes that you describe with language about what changed and why. It's really important to be descriptive because if you go and you look in your commit history and you're trying to understand why you did something a certain way, like a detective, because your memory will fade, but Git is forever. So what you do is you call Git add to add certain files to your stage to be committed. So if I add the .git attributes file and I do get status again, you'll see changes to be committed. This is called the stage. You'll see it's green here. We have that new file and you can remove files from the stage, but that's a little advanced. I wouldn't worry about that yet. And then we still have these files that are untracked. So then we know we want all these files and you'll see a lot of people by default just always do git add dash all. If we do git status now, everything's green. It's been added to the stage to be committed. And usually that works like 90% of the time that works, but sometimes maybe you've made a bunch of changes and you want to make separate commits from them. You can only, you can choose to selectively add certain files or even parts of a file. Again, that's more advanced. Don't worry about it. You know, git add and then you type out the path to the file or you can do git add dash dash all or you can do, I think that will work too. No, that doesn't work. I don't know. You can also do period. That's the same thing. So you add these to your stage and then what you do is you type git commit. When you type git commit, it will open up in your environment variables echo editor authoring the commit message. So my editor set to vim, to neo vim specifically. If you set it to VS code or sublime or g edit or whatever, you know, it'll open it there. So I type git commit and then it opens it and it says, you know, this is all comments and it tells you the files that are here. And I always start my project with an initial commit of the clean generated whatever the engine gives me because then I know that's what's there. And don't worry if you don't, if you don't know them and it opens them, you might be in for a hard time. But the basics of them is you press I to go into insert mode and then you type and then you press escape and then colon WQ to save it. But yeah, I would advise to not learn them and get at the same time and stuff. You know, use, use a GUI or, you know, set the editor path, the editor environment variable to, you know, the path to your editor. There's a lot of caveats with all this stuff. So if it is overwhelming, let me just acknowledge, like, get at the beginning is pretty overwhelming. But what I'll just say here is initialize new repository. I'll say initialize new project with Godot 4.0. And I just like to make it clear, you know, what version this was initialized with. So then save that, it creates the commit and you can see it did here. And now if we do git status, we're on branch main, would not worry about branches brand main and master used to be called master. It still might be called master, depending on the version of get you use is your branch. Branches are like a tree. You have the main trunk of the tree. That's your main branch you're working on. And then you can branch off of it and you can merge those branches back in. But really, when you're working by yourself, you'll probably just use main branch. So don't worry about branches yet, but just know that, like, if you want to experiment with something, you could branch off of main and do some experimenting and isolation and, you know, not have to commit to using it. So get status is a command you run a lot. Get commit is how you create your commits and then get log shows you the log of those commits. And you'll see this long hash kind of looking thing. It's called a shah, shah, the get shah. And that's our commit. That's the unique identifier for our commit. You can see I authored it and can see the date and you can see my message and you can write more detailed messages if you want. I generally do. But so now we have our get log. We have that. Let's go to GitHub and create a repository because this is where it's really valuable, right? You want to make these backups. So I have a GitHub account. We'll click new. And I'm going to call it gado get. And it's just an example. You know, how you name this is up to you, whatever. It's totally up to you. Using gado for a screencast. You can make a public or private. They're free now. You still have to pay to have private ones after a certain amount or maybe even any private ones. But public or private, I'll keep it public because I want to share this with you. And you can add a read me and a get ignore and a license. But I usually skip all that and just create my repository and don't do any of that. I'll add that stuff manually if I want. And then you can set it up in desktop if you're using GitHub for desktop or you can copy this URL and it even tells you how to push an existing repository. So it's pretty helpful. So I'll just copy that, right? So this says get remote at origin. Origin is a remote like it's a place where you want to push your get repository because your get repository exists in many different places. It exists on your computer and it can exist on any number of servers. It can exist on your other computer. If you have multiple computers and you can kind of push and pull between them all. So we'll add one called origin. Origin will just be GitHub and that's where we mainly push our code. This sets the branch to main and then we push our code. So get push is how we push code to different places. We're going to push origin and we're going to push the main branch to origin. And that's what all that stuff that GitHub gives you here does. And we'll talk more about pushing in a second. So now if you refresh this, now we have our project here and we can click here and view our commit history and you'll see it matches what we had before it. We click in here and you see there's a shortened version of the commit shot here. And let's just verify it matches 416C987. Yep, those match. So GitHub nicely shows your images and all your data. So yeah, we've got a new get repository. It's pushed up to GitHub. And we are off like a herd of turtles, you know. Now we can make our game and we'll go ahead and let's add a scene 2D. And I'll just call it main and save that. Drag an old Godot bot. No one's told me the robot's name yet. So I don't know. I don't know what to call the robot. And we'll add a script to main and we'll do the old favorite rotate with Delta. I'm ashamed. It's my only trick in the book. And then run it, select the current. And we'll see that sweet, sweet spinning icon. Now if we go back to the terminal, we do get status. You'll see that we've modified project.godot. And we have two new untracked files, main.gd and main.tscn. Main.gd is our gd script code that we wrote with the rotating. Tscn is the main scene that I created with the icon and save. But let's go ahead and we'll do get diff. This shows you, the get diff command shows you what has changed with the files that are being tracked with git. So it only shows us the difference of project.godot. It doesn't show us the diff here because we haven't tracked these files with Godot. So you'll see it's at the main run, the run main scene to main.tscn. So go back to get status. Get status is really clear. That command was get diff, just to remind you, get status again. Untracked files and modified files. We want to add all these to our stage and commit them. And this commit would be something like rotate the icon. And you could imagine instead of it being rotate the icon, maybe it's make player jump, maybe it's add enemy, maybe it's add level two, maybe it's refine level two, right? Whenever you do a piece of work that you consider to be done, that moves your project forward, create a commit. And I create a lot of commits. You want to err on the side of creating more commits, not fewer commits, because the more fidelity you have to the commits you make, the more useful they'll be to you. If you just go and do like three days of work and then commit it and just say like, made a bunch of changes, that's not very useful for historical purposes. And you will go back when you revisit your code base in years and try to understand why you did something the way you did it. You will go back and look at the get history, especially if you are making a big project. You're trying to help your future self by leaving comments and detailed get commit messages about what changed and why. So we'll just do get add dash all and we'll get status. And now all these changes have been added to the stage. And I want to show you how to view what's been added to the stage. So if you do get diff dash dash cached, that shows you the diff of the files that have been added to the stage. If you didn't add them to the stage, nothing would show up. But now we see, you know, we added our process function. We added our new scene and we set that to be the run main scene. So if we get status, we've got all that there. Now we could commit. Here's another tip on committing. If you do dash v, that's for verbose, it will show you below here the diff of what has changed. This is really helpful, I find, when writing detailed commits because it's really annoying to have to like switch back and forth to view the code that's changed when writing detailed commits. So we'll just say, make the add Godot robot icon and rotate it. And I'll just say like, this is really nice. It looks good, so fancy. You know, this is kind of a trivial thing, but I will write like detailed, detailed commits and save that. And now we do get status. Our branch is one ahead of our origin main. So that's what's on GitHub. We're gonna wanna push our code up. But if we do get log again, I just wanna show you. Now we have two commits. They show in order, in reverse order, reverse chronological order. So like the most recent ones are at the top. And that's get log. So we've got a lot of commands we're going through, but these are the basics of them. Then you can do get push. Before, remember, we did get push dash u origin main. Well, our local get repository knows that we wanna push it to origin. So you can just do get push and it will automatically push it up to GitHub so you can have that command be a bit shorter. And now when we go here, we see that we've got our two commits on GitHub and that most recent changes there. So that is, you know, you get in this flow and then you don't really think about it too much and you know, you just push it up there and you got it as a backup. It's safekeeping. If you are working on a game with other people, it unlocks another functionality of Git where you can make changes on branches and create pull requests where you say I wanna merge these changes in. So if you are working with other people, keep exploring this. It's really helpful because then there's less conflicts and there's less like divergence of what multiple people might be working on. And it's really foundational to, if you wanna contribute to the Godot engine on GitHub, you know, this is, yeah, this stuff is the foundation to all of how Godot is developed, whether it's people making pull requests, like this person, you know, made a pull request off their pick one branch and they're trying to merge it into master in Godot. But for your game projects, yeah, that's the core of it. Let's just add one more piece of functionality and we'll make it so that I'm not feeling very creative. So we'll do something I've done in other videos which is making our icon pause and stop rotation. So if we're rotating, we'll rotate it and then we'll add in the input, in the input callback, we'll just say if event that is action pressed, you are accept, which is the space bar, rotating is negated, rotating, run that. And now when we press the space bar, our body stops rotating. And so we do get status, right? Sorry, I have some shortcuts forget that like do what I do all the time, it's like muscle memory but let me ignore the GAP, the gap I just typed. That's short for get add dash P and that lets you go through a file and add certain chunk hunks and this is like yes, no, quit, all, delete as in, you know, don't add anymore and you know, this interface here is kind of maybe a lot, but anyway, this get add P is like just if you did get add all, you know, it would add main.gd to it but you know, I'll often do get add dash P and see like, okay, yeah, it's a way to review my code as I'm adding it to get. So like, you know, you'll catch bugs this way, right? You'll be like, oh, that's weird. I didn't notice that or that's kind of interesting because you're trying to like, a lot of this code stuff or this stuff with get for me is about like, it helps me write better code, it's a tool to use and it's not like eating your vegetables, right? And I think some people view it that way. Like I don't care if you use get or not, right? Like you could just like put it on Dropbox or iCloud, Drive or whatever, some OneDrive on Microsoft, whatever, you can push your project there and have it backed up. Like that's something I do care about. I want you to back up your games. That's really important and have it so in case your hard drive fails, you still have your games. For me, get is a tool that I use. It helps me write better code and I think make better software. So I think there's valid reasons to do that but I don't know why I started talking about why I don't care whether or not you use get. If you do want to use it, I'm hoping this video helps you. But you know, it's a tool to be used that has value but it's optional, especially if you're working solo. So I added main.gd changes there. I'll go ahead and I'll commit with verbosity and I'll say roads, toggle, Godot, robot, icon with spacebar. To help with motion sickness. I don't know, whatever. Like you're gonna add stuff to your game and you'll commit it and we'll push it up. Whoops. I had a typo but gets pretty smart these days and knows I meant that. And that pushes it up to GitHub. So that is the fundamentals of using get from the command line for game development. That's the like fidelity at which I make commits. And let me show you some of my example games that will give you a sense of that. So like here is a couple projects and this is Godot types, a bunch of prototypes I made with Godot. And also since I'm making my work open source creating detailed commits for other people to view should help them out and understand why I changed what I changed. So you'll see here, I follow a specific commit formatting. Don't worry about that. That's like more advanced, doesn't matter. It's just I have a tool that does that for me automatically. You can see here like in this game shooting gallery I was using a specific type of node. I was using a rigid body 3D but I wanted it to be just area 3D. So I changed it and I just commit when I changed it. And that seems trivial, but the thing is like sometimes Godot like might crash or like if you rename things it might cause problems. And if you can easily just like undo your changes with Git that's really valuable. So here I added a cursor and I added a sprite from Kenny and I'll note that in the comments of the Git commit. So I remember right, like or someone reads this commit and they see it and they're like where did that come from? And I can be like, oh yeah, it's a Kenny asset. I added some aiming to something and I watched a YouTube video that helped me. So I linked to that and you know, yeah, that's the level at which I commit things. Now let's go ahead and like break our code and I'll show you how to like get out of a tricky situation. So if we change that to that, that's just some junk code, whatever, our game doesn't run. If we go to Git status, we do Git diff and we see that that's there. To get, to lose that change, you know, when you do get status it gives you quite a bit of help. You know, you might be overwhelmed if you're not used to command line interfaces, but then once you get used to them it's like pretty fast and helpful. But Git tells you to use Git restore file to discard changes in the working directory. So you just do what it says. You do git restore main.gd. GST is my Git status. I'm sorry, this muscle memory stuff is bad for screen casting. And then when we change that, it actually updated automatically in the Godot script editor. And sometimes it might prompt you. So if it does, it does. If it doesn't, it doesn't. So that was Git restore. In the old days, back in my day, it used to be git checkout dash dash the file name, which is confusing because it's different than checking out a branch. So I think they renamed it. So I'll often do git checkout that, you know, that's muscle memory, but the new command these days is git restore. And if you wanna know more about any of these things, if you're new to the command line, you can do dash dash help. And it'll tell you more than you would ever care to know about any of this stuff. Git is such a robust tool. And I think maybe that's part of why it has a reputation of being hard to learn, but I think in summary, we've got git status, we've got git diff, we've got git push, we've got git restore to undo your changes. We've got git commit to create your commits. We've got git add to add files. You can do git add all dash dash all. And those are about the five to 10 commands you'll use day after day after day after day and you'll get used to it. And the more you use it, the easier it'll get. And I just thought it'd be helpful to open up GitHub desktop and show you what a GUI is like. There's one called Source Tree as well, but I have this installed and set up and I'm recommending using GitHub desktop, or I'm recommending putting your code on GitHub. So I figure why not just use the free Git client they have and they have a repository tutorial, which is cool. But we'll add an existing repository from our hard drive. And that is, if you're creating a new one in the GUI, it'd be a different experience. But for me, I've already got this repository. So we'll go ahead to game dev. Remember we set it up in screencasts and then we called it Godokit and you just click open. And then add repository. Now GitHub desktop is tracking this repository and you can change it up here. And this gives you a visual sense of what we were just experiencing. So you can click history and sh, gosh, get the heck out of here. And you can see all of our history of the commits, which is cool. And then let's make some changes in our code. Like we'll make it so that rotating is false by default. And then you press space to turn it on. Now if we go back to GitHub desktop, you'll see in changes tab, it shows this already here and shows main GD with that change. And if we had multiple files that changed, it would also change it. Like we could change this to be like robot. Then we gotta update this code too. But we'll make sure it runs. Okay, it works great. Now if we go back to GitHub desktop, now we see both of these changes. And you can like, the equivalent of git add in this GUI is these check boxes. So like, you check here, you check here, it tells you it's a modified file. So now we've checked these files. We're gonna add them to the commit. We'll describe it, right? We'll say, don't rotate robot by default. And then, you know, it was making me sick. Whatever, you know. And you click the commit button and that's the GUI version of git add and then git commit. And then it actually tells you that we have these changes that need to be pushed. And you can do command P or you can push origin and it goes ahead and does git push origin main for you. So, you know, that's like the same thing we just did and it's through a GUI. Use whatever you feel comfortable with and keep practicing it. Have fun with it. Like, I don't know, I put, I try to make myself laugh a little. Like, you know, should be fun. And I think that's enough of the basics of git. I hope, I hope this was helpful. I hope this wasn't just like throwing you into the deep end of the pool. But if you're interested in git, hopefully this helped you learn it. If you're new to git and you're not even, you don't know what it is. Maybe seek out some other resources first. But this is more about using git with gado from the command line and the fidelity at which I create commits. Thanks for watching. See you, bye.