Pushing a Unity Project to Github

Lance Gold
3 min readFeb 14, 2024

--

After some preliminary preparation, local work can be placed onto https://github.com for team access. Branches may also be created for work during development.

Github screen to begin creation of a new repository

At the remote Github site, complete information for project name, which will be the repository name.

Github display of options to create with a README file and Unity .gitignore template

After setting .gitignore template to Unity, checking read access to Public, and whether or not to begin with a README.md file, make a note of the main branch url.

The Github main branch url copy icon

On the local workstation, create a new Unity project with name and location, including Unity Cloud access if desired.

screen of Github final create steps

With the remote awaiting and the local project available, open a terminal to connect to the remote Github repo.

cd <”location of empty project folder”>

git init

git remote rm origin (if the origin is already set)

git remote add origin <url>

git fetch origin

Terminal screen with git commands to connect to Github

Initially, git may warn of LF CR/LF changes when adding project files, and output a verbose list of files in the project.

git add . (a decimal point wildcare char) This does not work with Visual Studio, so add (git add…) each directory individually.

git commit -m “message to explain circumstances of commit”

Screen with local git add and git commit commands

and then the final step. This should create a prompt for a github login:

git push origin main

or “git push origin master”

Screen with git push command

After a refresh, the coordinated project files appear on the remote Github main branch.

Github new main tree after initial project push

Now from this entry point with a local empty git project matching the remote Github main branch files, new branches may be created separating development according to function.

git branch
git branch dev
git branch
git switch dev
git branch
git branch inventory
git branch quest

git switch dev
— -< add a c# script devBranch > — -
git add .
git commit -m “Added Dev Script”
git switch inventory
git merge dev

— -< add a c# script inventory > — -

git add .
git commit -m “Added inventory script”
git switch dev
git merge inventory

git init
git push origin dev

— — — — < revert prior verion > — — —
git log
<q>
<highlight copy id hash of prior version>
git switch idhashofpriorversion

— — — -< revert to prior version as a branch > — — — -
git switch -b old-project-state idhashofpriorversion

— — — < revert to prior version of main > — —
git reset — hard idhashofpriorversion

git push — force origin master

--

--

No responses yet