What IS Git/GitHub?
Git is a free and open-source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.
GitHub is a cloud-based service that hosts a version control system called Git. It allows developers to collaborate and make changes to shared projects while keeping detailed track of their progress.
First, you will need to install Git. Go to https://git-scm.com/ and click the button on the PC image to download the latest version for your OS.
(NOTE: This is for Git v2.32.0. The installation process may vary in other versions.) Once the download finishes, open the downloaded file. It may ask to change your PC settings, so allow it to. Continue the installation process, leaving everything on it’s default settings (Make sure that Git Bash is definitely checked on the 2nd page). You may want to tick desktop icon and daily update checks too.
Navigating to your Unity project/s:
Once installed, check “Launch Git Bash” then click “Finish”. It will open the command-line tool that we will be using to communicate between our computer and web servers. You’re now ready to use Git!
While it may be new and unusual to you, navigating folders using Git is quite simple once you learn how.
I have a Unity project called “Version Control Examples” in the directory “C:/Users/Vincent/Documents/Development/”.
Starting from a newly opened command-line window (that we just installed and launched), I can navigate to this directory using the “cd” or “change directory” command, then typing the directory (folder) name. The “ls” or “list” command also shows all sub-directories inside the current directory.
To simplify the process shown in the above gif, I could also just type the single line: “cd documents/development/version\ control\ examples” and end up in the same place. You can also use the TAB key to auto-fill directory names after typing the first few characters of the name.
You may have noticed that I’ve used backwards slashes in the directory name “version\ control\ examples” even though the actual folder name is “Version Control Examples”. This is because this command-line terminal cannot differentiate between spaces between commands (E.g. “cd documents”) and spaces in a folder name (E.g. “version control examples”), so we need to use “\” to indicate that it is a folder-name space.
Creating a GitHub repository:
Creating a repository is an incredibly simple process. Once you’ve created or logged in to your GitHub account at https://github.com, click the “New” button near your list of repositories.
Connecting your online GitHub repository to your local Unity project:
Again, a pretty simple process.
- Copy the repository URL
2. Use “git init” to create a .git file, and “git remote add origin <The URL you copied>” to connect the local project to the remote repository server
3. Verify that the connection worked successfully. (fetch) and (push) indicate that we have permission to both send and receive from the repository
If at any point you have trouble, or forget a command, “git --help” will show all commands.
What’s next? Committing and Pulling for our Unity project!
I’ll go into this in the next Medium tomorrow!