Using GitHub with Unity effectively! Improve your workflow!

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
what is up guys welcome to Barden my name is Heinrich and today I'm gonna show you how you can use github and unity to protect your projects and improve your workflow here are some time stamps at different parts of the tutorial so let's begin first of all what is git git is a free and open-source version control system what that basically means is that it's a system that we can use to manage and track changes in our project as well as keep records of those changes to interact with get we're going to use github github allows us to create and manage git repositories the repository can be thought of as the root project folder for your project now in order to interact with our repositories we can either use the command line or we can use github desktop client as well as a lot of other different clients personally I use the desktop client as I find it to be very user-friendly and very beginner friendly but you can use whatever you're most comfortable with so now let's get into getting everything set up the first thing we're going to need is yet you can download get at git - SCM com the link will be in the description on this page you can just navigate down here to the download button at the bottom left download for Windows or if you're using Mac there should be a download for Mac as well but just a little side note I'm only familiar doing this on Windows but I believe the process is very similar so once you've downloaded and installed this you can go ahead and come over to github comm where we can then create an account I already have an account so I'm just going to log in this is your github profile page if you don't see this after you logged in you can come up to the top right over here click the whole drop down and just go to your profile there's a lot of information here that we don't really need our most important thing is this repository staff here we will have a list of all of our repositories now the last thing we need to do to get set up is download github desktop and you can get that from desktop github.com again just click the download button and follow the instructions and then once you're done with that we can get started okay now that everything's set up we can go ahead and create our first repository so on github.com in our repositories tab go ahead and click new this will take us to the create a new repository window we can start off by specifying a repository and as you can see spaces are not allowed in the name for the repository but github takes care of that for us next we can give the project a description and then we can specify whether we want this repository to be public or private if the repository is public that means anybody can see the repository but you can still choose who gets to commit to your repository and we'll get into what a commit is in just a second if you make a repository private that means only you and the selected people that you choose can see the repository and commit to the repository next we can choose to initialize the repository for a readme and the readme is generally just to give extra information about the project so I'll just go ahead and take that next we have the option to add a git ignore file now what I get ignore file does is it makes get exclude certain files that aren't necessary to be backed up a bunch of meta files that get generated when you start the program and get to leader proposed the program things like that lucky for us github has a predefined unity get ignore file that we can start off with once you have all this filled in you can just go ahead and click create repository and there we go we now have our first repository as you can see here are the files in the repository we have our get ignore file and our readme file if we click on the readme file we can view its contents and currently the readme only has the project name and the description underneath so yeah that's it that's our first repository now let's go ahead and take a look at commits to demonstrate this let's go ahead and edit the readme file after we've made this change we can go ahead and scroll down and it'll give us the option to commit changes now what a commit is is basically like saving your progress to the project to your repository saying I've made these changes and I want this to get added to the permanent record of the repository so we can start off by giving the commit and name and it has pre generated updated readme for us which is good enough name to start off with and then we can optionally give it a extended description if there was more complicated things happening in the commit we can just leave that empty in this case next we have the option to commit directly to the master branch or we can create a new branch we'll get into this into second for now let's just go ahead and commit changes as you can see our readme file now shows our change this is going to be my first commit if we go back to the root directory so click on our project name up here you can see that we now have two commits if we go ahead and click on the commits button over here we can see the history of our different commits over here we have the initial commit which automatically happens when we create the repository and over here we updated our readme and that's the basics of committing so now that we've created this repository let's talk about how we get this repository on our local machines let's go ahead and go back to the root project directory and if we take a look at the screen code button over here on the right we have a bunch of different options we can download the whole project as a zip and over here it gives us the option to open with github desktop another thing we have over here is a URL and we'll get into how to use that in just a second so before we do anything with this let's go ahead and open up github desktop the first time you open it up it's going to ask you to log in to your github account and it'll probably also ask you for a name and email but once you've done that you should be greeted with a page that looks something like this so over here we have the option to clone a repository from the internet if we click on this on this first tab github.com we have a list of all of our repositories if we're logged in so over here you can see we have our very cool game project repository so our one option is just to click on this and then click clone you also have to choose your local path so where you want the repository to be another option we have is to use this URL which is where this URL on this page comes from so if we click on the green code button copy this URL and then paste that in here we now have the option to clone this repository again you have to choose your local path I'm just going to leave it in my game dev folder we can then go ahead and click clone this will now get all the files from github servers and create a local copy of it on our machines this is the window you should see if you're currently in a specific repository up here at the top left you can see current repository is very cool game project here we have two tabs we have our changes and our history tab any changes we made to the project will show up over here alternatively we can go to history to see all of our commits so here we have our initial commit and here we update it to read me over here on the right we can see the different changes that happened with these commits and that's it that's how you clone a repository from github servers onto your local machines now let's talk about adding our unity gain to our folders so if we navigate to our repository so I have mine under documents gamedev and over here I have very cool game project repository if I open this I can see my readme I might get ignore file this dot git folder is used by get itself so we don't need to really worry about that so now let's go ahead and create a new game that we want to be part of this repository so go ahead and open up unity and then let's click new and let's just give it a name and then go ahead and under location choose your repository we can then click create and as you can see the next big thing has already been added to our folder like it should so once the project has been created the first thing we want to do is come up to edit project settings and then under the editor tab come to version control and set the mode to visible meta files and under acid sterilization set the mode to force text you only have to do this once but it's good to check every now and then now if we go to our desktop client we should see all the files that have just been created but as you can see there's 3795 changed files and that's not correct because as you can see we still have a bunch of meta files in here that we don't want there's just a whole bunch of unnecessary files now this has to do with how our git ignore file is set up if we go to a repository or get ignore file is currently expecting all of these folders to be at the same level so what we can do is we could just move all of these one directory up so that they're on the same level another option that we have is to edit architect nor file and just remove these slashes if we go ahead and save that and go back to our desktop client you can see the amount of files that have been changed or picked up as changes is only 20 these are all the important asset files and doesn't include any of the unnecessary meta files so now we can do is commit this so at the bottom over here we give the name for the commit or this summary and then we also have the option to give it a description if we then say commit to master we have now committed this change to our repository so if we look in history over here we created a new project now it's important to note that this commit is only local to our machine and if we head to github you'll see that none of these files have been added yet and that's because we still need to push our changes to the server this is indicated by this little up arrow next to our history so in order to push our changes we can just come up to this button over here where it says push origin click that and it'll push our changes to the servers so now I can see the arrow is gone and if we go back to github and refresh you can see our game folder has been added we have our acids everything we need perfect now let's say you already have a game that you want to put into a repository the process is gonna be very similar if we go to our desktop client we can go ahead and come up to file and say add a local repository now this add local repository option is if you already have a repository on your machine that you just want to have github desktop pick up but if we go ahead and choose our game folder as the repository so over here I have my awesome tutorial series that you should totally check out if we just click that and say select folder it'll say this directory does not appear to be a git repository would you like to create a repository here instead so we can go ahead and click on that and this will take us to create a new repository tab this is the same thing that we will be greeted with if we were to just create a new repository with the desktop client instead of on github.com itself so again now we have the option to give it a name and a description the local path will be locked because it's the folder that we chose I'm not going to initialize it if a readme this time we can just go ahead and add our unity git ignore file if we then go ahead and click create repository and just let it do its thing you can see that our current repository has now been changed to our awesome tutorial series but there are no changes that's because when we create the repository it commits all the files as part of the initial commit so as you can see 409 files have been committed instead of 23 because this project is quite a bit bigger than a new unity project now if we go back to github and we go to our repositories which is just under your profile there's a quick way to get there you can see that this new repository is not part of the list that's because similarly to having to push a commit we need to publish a repository so we go back to the desktop client you can see where we had the push button last time we have the option to publish repository so if we click that it'll again allow us to give the repository a description and over here we have the option to keep this code private if you uncheck this it'll create a public repository and if you keep the stick it'll create a private repository so now if we say publish repository and then go ahead and go back to github and refresh this as you can see the awesome two trolls here is that you should totally check out is now part of our repositories awesome now that's basically all you need to know to get started with git but I'm going to share some of my personal experience and how I work with git in order to improve my own workflow and just to help keep our repositories neat and tidy so the first thing we're going to talk about is branches so if we go ahead and open up this awesome controls here is that you should totally check out you can see over here it says master this means that we are on our master branch now generally rule of thumb you want the master branch to be a working version of your game so when you make changes to your code you're never making it on your master branch so if we go ahead and open up this project in unity you can see here I have the latest working version of my game now I want to make some changes to this project I'm going to go into the next stage of development and I'm going to add a third enemy or something like that what I want to do is come down to github and up here at the top we can see our current branch so currently it's master we don't have any other branches yet but we have the option to create a new branch so we go ahead and click new branch we can give this branch a name now there's a whole bunch of different standards for choosing a branch name again if you're working by yourself this doesn't really matter and usually if you work in a team or for a different company the standard will be given to you what I like to do is give it the prefix proto which means I'm busy prototyping something and then a short description of what I'm prototyping so let's just say we want to work on the character's jump so I just say better jump if we then go ahead and create branch you can see that it automatically updated our current branch to proto better jump now just like we had to publish the repository we have to publish this branch so you can click up here or on the right over here once that has been published we can go ahead and come to github if we refresh this you'll see there's two branches now we have our master and we have our better jump now let's go make some changes to our code so let's just imagine I am making some mad changes to my code if we save this and then head back to the desktop client you can see that it picks up a change over here it says we've added wow much code so now when we commit this we want to make sure we give it a descriptive title now I didn't actually work on the jump code but we're just pretending over here if we commit this and then push to origin if we go look at our history you can see that we have our initial commit and then we made changes to our jump code now if you want to take a look at our working version of the game we can go ahead and just on-the-fly change our branch to our master branch when this happens if we go ahead and look at the code you can see that our change disappears if we change back to our better jump branch go ahead and take a look at the code you can see that it's back so this is what makes branches so nice we can go ahead and just mess around if our code prototype things make it messy without fearing that we're going to ruin our working version of the game if we end up completely breaking things we can just make a new branch and then once we're happy with the things that we've created we can just go ahead and put our changes back into master with a thing called merging so let's go ahead and go make some more changes and let's commit those changes and then push it and then let's make one more change just for good measure we can now see that we have a nice history of commits on our branch if we go ahead and look on github itself you can see that currently on the master branch we have one commit and then if we change this to our better jump branch we have four commits and over here it'll tell us that this branch is three commits ahead of master now let's say we're happy with the changes that we made in our better jump branch we want to add this back into master so from the desktop client we can come over to changes and we can come click on create pull request if we click on this it'll open up the browser again and over here we can give a title for the pull request we can leave a comment again these things are a lot more important when you're working in a team you want the people reviewing your code to know what you did so they can know better what they need to look for I'm just going to leave this as default and say create pull request now it's going to check to see if our code can be merged it'll make sure that there are no conflicts over here we can go ahead and look at the commits for this merge you can look at the files that have been changed we can look all the changes this is going to bring into our project which is pretty neat so now let's just go ahead and click on merge pull request and then click confirm merge know tells us that the pull request has successfully been merged and closed that means all the changes that we've made in our proto better jump branch has been added to our master branch we now have the option to delete this branch but I generally don't but it is a good way to keep things tidy so if we go back to our code and we look at the master branch let's go to our script that we changed as you can see the comments that we added to our code is now part of our master branch again master branch is holding the latest working version of our project so if we're going to make any other changes we need to make another branch okay now let's take a look at undoing mistakes so let's go back to our desktop client and then let's create a new branch we're gonna call this melee attacks just for fun again it's all just make-believe right now and we can create our branch based on master so we have the option to branch off of different branches if we wanted to what we're going to keep it simple and just branch off of master for now once we've created the branch don't forget to publish it and let's go ahead and make some changes to our project again let's say this time we want to move our enemies around a bit so I'm going to move enemy two over here instead and now something to keep in mind is when using version control it's good to commit as often as possible the more commits you have for smaller changes the better record of your history do you have and the more precisely you can change things in the past if you need to but it's not the end of the world if you write a whole script and only commit then it's just good practice so after having moved enemy 2 I'm going to come back to the desktop client oh wait I need to save this come over here as you can see we've updated our main dot unity file changing the position of the player let's just go ahead and commit that don't forget to push it and now let's say I move him again this time I'm gonna move him up here let's save that and commit again commit that and push it now going back to unity let's say okay I'm not happy with the color of my Archer let me go ahead and change that it would be a bit excessive and let's just make him completely red if we save this and we go ahead and look at our desktop client as you can see the main audio file has been updated again but now let's say oh I didn't actually want to make this change now instead of reverting the color over here what we can do is in the desktop client what we can do is just undo the changes over here now if there's a bunch of different files you can choose specific files to undo changes from or if you just right click at the top over here you can say discard all changes it'll ask you to confirm that that's what you want to do you can say yes now if we go back to unity it'll detect there's been a change so we can just say reload and as you can see our archer is now back to normal but now let's say we actually do want to change the color save that go back to get and let's just can commit that and now we can push it so now we currently have our archers standing at the top over here and he is red but now let's say again oh we actually did not want to make him red but we've committed the changes so how do we undo this without changing the color over here again again pretend that the changes are a lot more complicated than just changing the color what we can do is we can revert a commit so if we come to our history we have the history of all of our commits at the top here you can see we change the archer color if we right-click on this we have the option to revert this commit what that means is it's going to take this commit and undo the changes and basically restore to the state of the previous commit so where we moved the archer again but it doesn't delete this commit so you'll see if we click revert this commit we actually have another commit this time it's called revert changed archer color so this means even though we basically got rid of these changes we still have a history of this change which is pretty cool so we go back to unity click reload as you can see our Archer is back to the normal color this is awesome now you'll see that this commit has not been pushed so don't forget to push it now let's say we want to put the archer back in its initial position we can again just come to our history and revert these two move it positions so if we revert this commit and then revert this commit you can see we now have two new commits that we can push and then if we come back to unity reload you can see the archer is back in the initial commit so essentially we are currently back to this initial commit but yeah hopefully I left you guys a good starting point to getting used to using git in your own projects to keep your work safe you don't want to lose it when your hard drive inevitably breaks or when you accidentally write some bad code if you guys would like me to dive deeper into things that we can do with it I would be happy to do so so just let me know otherwise if you're just looking to learn some more I'll have some links in the description to handy videos with regards to using git appropriately so that's gonna be all for now I would just like to thank all of my supporters and wonderful people on patreon and a huge special thanks to triac Cody Lee Pyrrha says and Miguel gray I hope you guys all have a wonderful day
Info
Channel: Bardent
Views: 29,804
Rating: undefined out of 5
Keywords: Unity, Git, Github, branch, branches, merges, merge, revert, how, to, use
Id: WH7qDUYHGK8
Channel Id: undefined
Length: 23min 30sec (1410 seconds)
Published: Wed Jul 15 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.