Setting up Git for Unity
GameDevHq day 1.
Git is downright essential when working on software projects with multiple people, but it can also be a lifesaver when working alone.
Step one, downloading and installing Git form
Your system will be detected, and you can download the relevant version(Windows in my case.)
After downloading the Git installer run it and keep everything on default.
Now its time to make Git work with unity
Using your file explorer navigate to the folder containing you Unity projects, and right click. You should now see two new options, select “Git Bash Here”
You will now see the gitbash command prompt
From here you can navigate like it’s the 80s again. First off type “ls” to see a list of contents in your current folder.
I want to enter the version control folder I made earlier to do this type “cd ver ” then press tab, this will fill the folder name automatically. Then press enter.
You are now in the Version control folder. leave this window open and move over to github to make a repository. If you don’t have an account make one and go your main page.
From github click on the “+” in the top right and make a new repository.
Give your repository an appropriate name, and specific to our needs with unity, select the “.gitignore” box search for and select unity from the drop-down. You can now create your repository.
On the repository page click on code and then the clipboard to copy the server address.
We can now return to gitbash and type in ”git init”. This initializes the folder for git.
Now type “git remote add origin your repository address” this will link our working folder to the repository of your selected address.
Now we can type “git pull origin main” this pulls the content from the server to our working folder.
Next we want to sync the files currently in our unity folder to our github repository. To do this type “git add .” this will add all the files in the folder to the main branch.
You can use the command “git status” to show which are added to the commit.
now we can type ”git commit -m “enter your commit message here” ” this will commit your unity folder and project files to the git repository.
We can now push this commit to the main branch with the command
”git push origin master”.
When gitbash finishes pushing your folder contents, you can head over to github and your commits will be available in the repository we created earlier.
Something that can be quite helpful moving forward is the “git help” command. This will list all the basic commands available in gitbash.
Hope this helps, thanks for reading.