Creating a Unity GITHUB Repository!
The first thing you want to do, is create your new Unity project and locate that file path in your command line! If you want a shortcut, just go to the folder path you want it open in, right click, and open git bash.
Now, login to your git hub account and go into the repositories tab. Once you are here click the new button on the top left!
Fill in the necessary information, you can use either Public or Private. For this example we are just going to use public. To explain what each one does though, if you select public, anyone can see the repository but you chose who has commit actions. If its private, only those you invite will see it. Nest option we will select is the .gitignore and type in Unity. We do this because Unity has a lot of extra folders that we just don't want to see at this time! Once all this is filled out, go ahead and Create repository!
Next we need to connect our Unity project with the github server! To start, click the code dropdown and copy the https link. So lets take a look at our command line!
Here, you are going to type git init. This is telling git hub, to initialize and create a main or formerly known as master branch. You will see it has been completed and see the name of the branch in blue letters. If yours says master, you will need to change it to avoid headaches! To do that, type, “git branch -m master main”. This will rename it to main.
To connect the server to the repository, we now need to link it. In the command line enter “git remote add origin” and then paste the link we previously copied from git hub. Once you hit enter we can now double check to see that it worked, to do that, type “git remote -v”. You should see a screen similar to the screen below.
Next we need to make sure all the information in our Unity project and our repository is up to date! There is 3 steps we need to take, as a good rule of thumb always try and keep it in this order! Fist we need to pull, then commit, then push! If you need a way to remember this, think of Kitara in Avatar the Last Air bender. When she is water bending, she needs to pull the water together, then she needs to decide if she wants to commit to striking her enemy, then she has to push it!
Now that we can remember pull, commit, push lets get into it! First we need to pull from our origin (github). To do this type git pull origin main.
If you encountered an error here, double check and make sure your have changed your branch name to main and not master!
Once that is completed, we can type get status and see what needs to be committed and sent to the repository. In this case, we want to send all of them, just type “git add .”. The period lets us move all of them instead of just one folder at a time! Now we need to commit, type (git commit -m “”). Inside of the quotation marks, write a short message on what you are adding so that you can keep track of what you have done! Ex. git commit -m “creating unity project”
Two steps down! Our last step now is, you guessed it, push! Now to push everything we just committed type “git push origin main”.
Congratulations! To see our progress, go back to github and refresh your repository, you should now see all the folders we just moved!