Project 1: Space Shooter
How to start a project in Unity
And linking it to a repository in GitHub
To start a new project in Unity, open the Unity Hub, go to the Projects tab and push the New project button. If you have multiple versions of Unity installed, choose the one you like to use from the top. Then choose which type of project you want to do, for my first project I will do a 2.5D shooter style game so I choose the 3D core project. Give it a name and select where to save it and click the Create project button.
While Unity starts the project I will head to GitHub, and start a new repository for my project. I usually match the name of my project with the name of the repository, so that it is easier to find later on.
Because I will not have anything that I want to keep a secret in my project I choose the public option. Which means that everyone can see everything that I’ve done for the project. The opposite is to make the repository private, then only the owner and those that have been given permission can access the repository.
Last thing to select is to add a .gitignore file specifically for Unity. This file will list all the files and folders that are needed by the project, but can be omitted from the repository, because they can be reproduced by Unity when the project is run for the first time in another computer. Then all I have to do is to push the Create repository button and the repository has been created.
Depending on how you want to make a connection to the GitHub repository there are three options to choose from. The https and GitHub CLI options are less involved methods, whereas the SSH takes a bit more to set up, but works without problems once it is up and running. That is why I will be using that option, but all three are good.
When I have copied the SSH address it is time to head to the Git Bash and set my project to use Git. First I have to navigate to the project, then I have to initialize the project for Git, after that I have to add my remote repository for my project and check to see if the connection was done.
Commands used for Git were:
git remote add origin "address to the remote repository"
git remote -v
Now that I have this done it is time to make my first pull from the repository to my project, the only file that should arrive is the .gitignore. The origin refers to the remote repository and the main refers to the branch into which I want to pull the .gitignore file. Once I have that, I can push my project to GitHub.
The add command adds files and folders to the commit, with the option “.” it adds all the files and folders that had any changes. The command commit prepares everything for the push, the flag -m allows me to write a comment for my commit at the same line, otherwise it would open up the editor that I chose to use with Git for making the comment.
Lastly the command push sends it all to the repository. Since this was my first push I used the flag -u to add the remote to my upstream, I also specified to which repository and branch. Later on when I push from my main to the repository I can use only the push command without the origin and main, the same goes for pull.
Commands used were:
git pull origin main
git add .
git commit -m "Comment"
git push -u origin main
Now all I have to do is to refresh my GitHub repository page and see that my push succeeded.