Objective: Get familiar with the git commands and learn how to create repositories from zero in github.
Install GIT from https://git-scm.com/.
Click next in everything until it is installed.
In github, create a new repository ‘VersionControlPrueba’, we can select between Public and Private.
The important part is to add a .gitignore file with ‘Unity’ option selected.
Finish selecting ‘create repository’.
Create a Unity project.
From the unity project folder we can call git bash console, using the mouse right button, click on ‘Git Bash Here’.
Automatically it will open the git console in the directory of our Unity project folder.
— — — — — INIT
First we initialize a repository.
Second we need to Identify ourselves using the next commands.
NEXT — — — — — REMOTE
We need to communicate the Unity project with the git repository we first create (VersionControlPrueba)
Let’s first copy the URL from our git repository, click on the ‘Code’ button.
GIT REMOTE ADD
In console we will write the command: git remote add <remote name> <remote URL>.
The remote name usually used is ‘origin’.
The remote URL is the one we copy from our git repository.
With this we will be seen a .git folder in our unity project folder OR…..
Use GIT REMOTE -V to verify
NEXT — — — — — STATUS
We need to see the status of our project, let’s see the objects that are currently outside of the repository, GIT STATUS.
We don’t have any commits yet and all those red folders are out of our git repository.
As we can see we have ‘On branch master’. The brach are used to storage different changes of our project, if there is something we are not really sure about and we don’t want to add those changes inside our last update, then we can create a branch and commit those changes inside this new branch, and we can have the new changes inside our project and the last version without them. To create a new branch: GIT BRANCH name_branch.
NEXT — — — — — ADD
Let’s add files, if we want just one file we use GIT ADD file_name, if not then we use GIT ADD . , if there is an error in some files then use GIT ADD — IGNORE-ERRORS . , do not forget the dot which indicates ‘all’
To see the files added we use once again STATUS command
NEXT — — — — — COMMIT
We have three important commands PULL, PUSH and COMMIT, when we are already working with a project the first thing we need to do is to use PULL so we can update and start working with the latest version, but now we are doing a first use so after using ADD we need to commit and left a message to know what the changes are referring to.
NEXT — — — — — PUSH
Finally, we need to push the commit in our remote repository, right now we are using the master branch so we will be using it.
To list all existing branches GIT BRANCH
To push commits we use GIT PUSH remote_name branch_name
If we go to github, we will see all the files we add and commit.