Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
April 30, 2021 02:04 pm GMT

Using GitHub with Unity Projects

Introduction

Now that we've Installed Unity and Git, it's time we move on to using GitHub with Unity projects.

Let's get started!

Create a New Unity Project

We'll need a project to work with, so let's create a new one to use throughout the post. I'll make a new 2D project named GitHub_With_Unity.

Unity Hub New Project

Initialize a Local Git Repository

With our project created, we can initialize a local git repository by changing to the new project directory and using the git init. We now have a local git repository initialized for our project.

There's a bit of a problem, though, in terms of optimization of our repository storage. Let's take a look at the untracked files known to Git at by default using git status.

Assets/Library/Logs/Packages/ProjectSettings/Temp/UserSettings/

We don't need to store the majority of these directories in our repository. Unity will generate them as needed when opening the project.

We can tell Git to ignore files and directories using a .gitignore file that lives at the root of the project. Luckily, you don't need to create this file from scratch!

Let's check it out.

Ignore Unnecessary Files

Let's visit gitignore.io to create a Unity-specific gitignore file. Type Unity in the field and select "Unity" from the dropdown, and click "Create."

gitignore.io

You'll be navigated to the latest Unity gitignore file that you can then save directly to the root of your project by either copying and pasting the content into a new .gitignore file or saving directly from the browser and into your root project (Ctrl + s on Windows, Cmd + s on macOS).

With that file in place, we can check the status once more to see that Git acknowledges only the Assets, Packages, and ProjectSettings directories.

    Assets/    Packages/    ProjectSettings/

That's much better. Let's make the initial commit.

    git add .    git commit -m "Initial commit"

Now we need a remote repository on GitHub so we can push our changes. Let's do that easily with the GitHub CLI.

GitHub CLI Website

Create Remote Repository

I'll obtain the GitHub CLI via Chocolatey.

choco install gh

In order for the CLI to access our repositories, we will need to authenticate using gh auth login, which will walk you through the steps to authenticate.

To create a repository on GitHub based on our project, change the directory to the root of the project and run:

gh repo create

You'll need to provide the repository name and description (or press enter to take the defaults) and set the visibility. Once confirmed, the origin remote will be added and the remote repository created for you. Check it out by viewing your repositories on GitHub.

Finally, it's time to push our initial commit.

git push --set-upstream origin master

Summary

Now you know how to initialize a repository from your current project, add a .gitignore file to eliminate unnecessary files from the repository and create a new remote repository on GitHub.

I hope you found this helpful!


Original Link: https://dev.to/justinhhorner/using-github-with-unity-projects-594b

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To