Probably the coolest thing I learned this week, is how to better use GitHub with Unity. One of the problems with Unity is there are a lot of tiny files and some of them have exceptionally long file names.
A quick Google search of the term “how to store Unity files on GitHub” gave me an interesting result: GitHub for Unity. This is an open source project which adds GitHub directly into Unity. It’s almost like working with GitHub desktop, only within Unity itself. You can choose the files you want to add, enter your commit message, and then commit to main all from Unity. But this still didn’t solve the problem of these crazy long file names that don’t seem to fit nicely into GitHub.
Please refer to the list of known issues, and make sure you have backups of your work before trying it out.
From version 0.19 onwards, the location of the plugin has moved to
Assets/Plugins/GitHub. If you have version 0.18 or lower, you need to delete the
Assets/Editor/GitHub folder before you install newer versions. You should exit Unity and delete the folder from Explorer/Finder, as Unity will not unload native libraries while it's running. Also, remember to update your
Building and Contributing
Please read the How to Build document for information on how to build GitHub for Unity.
That’s when one of my viewers (remember I am streaming while I’m learning) chimed in and said I should use the command line. I’ve been doing a lot of work using the GitHub CLI and it’s been amazing. Being able to clone, fork, create repos and more from the terminal makes life a lot easier. I totally forgot (or rather didn’t really know how) the command line allows you to make lots of changes all at once.
You’ve probably heard of
.gitignore, which means you specifically identify files for git to ignore; or rather not bother committing them to your repo. If you want all your files in one place then this isn’t really an option.
So what do you do to get all these long file names onto GitHub? Use the command line. Here’s the commands we discovered to help you commit your Unity files to GitHub.
Make sure you have the GitHub CLI installed:
This command will tell you whether the CLI is installed, as well as information about what version you have. Plus it gives you a list of useful commands to get you started.
Next you need to navigate to your local git folder:
cd #add your file location for your local project here
Now we need to change all the long file names:
git config --system core.longpaths true
It will look like nothing happens, but all the names changed. If this doesn't work for you, then run your terminal as admin. Also, make sure you have Unity closed in order to do the above step. Otherwise you'll get
permission denied errors.
Then add all the files to your local git:
git add .
add . means that you're all all the files in your local directory.
Commit all the changes:
Lots of changes will happen, and colours. Make sure you then finalise the commit by adding the commit message:
git commit -m #add your commit message in here
This might take a while depending on how big the repo is.
At this stage they are still on your local machine. Now you just need to add them to GitHub. Do this by using:
I had a lot of fun learning about this and really excited to see some more open source projects as we stream. If you want to join in on these streams, follow me on Twitch and tune in when we go live. Guaranteed fun times, learning, and lots of great networking.
If want to watch these recordings then check out the first and second streams on Unity game dev.