6

Using GitHub with Unity Projects

 3 years ago
source link: https://dev.to/justinhhorner/using-github-with-unity-projects-594b
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

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.

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/
Enter fullscreen modeExit fullscreen mode

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."

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/
Enter fullscreen modeExit fullscreen mode

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

    git add .
    git commit -m "Initial commit"
Enter fullscreen modeExit fullscreen mode

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

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!


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK