Version Control 2.0
Using GitHub
Download Git for your respective OS @ https://git-scm.com/
Install Git (Default settings is fine)
Create a new Unity Project and name is VersionControlExample
In GitBash Navigate to your project location
Go to github.com and create a new repository. (VersionControlExample2). Set it to public and add a .gitignore template for Unity. Click Create
Copy the url of the git server (in my case ) https://github.com/xrtraptor/VersionControlExample2.git
To intialize the project run the commant (git init)
Add the remote server (git remote add origin https://github.com/xrtraptor/VersionControlExample2.git)
To verify that the commit took place run the command (git remote -v)
Pull from the server using (git pull)
A specific branch must be chosen.
if you type (git brach) it shows the branches that are available. If only the main branch exists than nothing will appear.
To pull from the main branch run (git pull origin main)
If you run (git branch) now it will show your main branch.
If you type (git status) you will see everything that needs to be added to the project.
If you want to add the assets folder to the repo (git add .)
This adds all tracked objects and now everything will be green. check with (git status)
Now create a commit (git commit — m “Test”)
Now we must push to the server.
In the projectr add a c# script and a cube to the scene. When done go back and run (git status). There will be changes.
add them, commit them, and push them to the server.
To create another working branch named dev run (git branch dev) and to see if it was created run (git branch)
If you want to switch over to the dev branch (git checkout dev)
So now dev is independent of the main branch. Changes from dev can always be merged into the main.
Create 2 more branches called quest and inventory
on the dev branch add a script. let’s add commit and push.
(git push origin dev) to push to the dev branch
Say we need files from another branch so let’s merge dev and inventory. So let’s move over to the inventory branch (git checkout inventory) and then let’s merge using (git merge dev).
Add another script called inventory. add and commit.
Now to add the changes in inventory let’s merge it into dev. (git checkout dev) and then let’s merge using (git merge inventory).
Push the new updates. (git push origin dev)
Let’s move all of the changes from the dev branch into the main.
(git checkout main) and then let’s merge using (git merge dev).
and push to the main.
To look at all previous commits use (git log)
If you want to go back in time go to (git checkout hashvalue)
to go back to main just switch back.
You could always turn that to it’s own branch using (git checkout -b old-project-state c0a8b1e7cb9884bef46d1a1c7c155d1c7d5dcd04)
You now have an old save if wanted.
Now to fully reset all changes of a branch to a place and time you can do (git reset — hard hashcode) and now it’s back in time. To reset the origin server (git push — — force origin main).
Now the project will be back to where you reset on that branch.