Getting Started: Let’s Git down to business
Objective: Explain Git and why we use it.
Git! What is it? Why would we use it?
What is Git?
Git is the modern day version of saving your work over and over again. The difference is instead of seeing folders with savedfile, savedfile2, savedfile2updated, savedfile2updatedfinal, savedfile2updatedfinalrealfinal and so on, you have a nice folder on your PC (or a Laptop or Mac, Git isn’t BIOS).
Git allows you to keep revisions of your work but rather than having to remember when things worked or which save had the last or best working version, Git maintains a revision log with dates and comments of what was added, removed or changed in the version. It allows you to save multiple versions of your work ,which is great for projects that are split into parts, allowing multiple people to manage different parts of the same project without worrying that one or the other may cause an issue. Theres always the option to go back, whether its been 1, 10 or 1000 saves later.
Git allows you to save your work, this we know. But Git always you to Push your work to the cloud, the ultimate backup. Git integrated with services like GitHub which allow you to set up a project folder on your own account. These projects or repositories can be set up as Public for people to share work or allows others to view your work. They can also be Private giving you the choice of who can see, contribute or download a copy of your repository.
Where to Git it?
Git can be downloaded for free(always nice) from https://git-scm.com/
For most the default installation will work fine its just couple of clicks, install the Git Bash (Looks and feels a bit like Windows Command Prompt). For those who like to run third party consoles, don’t worry you can still use CMDer etc. (Just remember to restart the console after installing Git).
Something that will always be helpful when using and starting off with any programs is a good cheatsheet.
You could always read the documentation but who wants to do that…
Firstly lets open Git Bash. You can choose to click the Windows start button and search or hit the windows key on the keyboard but I find the best option is right click inside the folder you want to use and click Git Bash here.
Once inside the first thing to run is help, just to get an idea of what commands and options are available.
As we’re just starting lets initialize the folder
Before we continue lets get ready to put our project somewhere. For now lets get signed up on GitHub
Once signed up, lets create our first repository by clicking on new.
Lets set up the repository. Choose your repository name. Every repository has to have a unique name linked to your account. For this I’ll go with GitDemo.
Another GitHub user can have that repository name, it just has to be unique to your repositories. For the demo I’ll choose a public repository.
I’ll skill the addition steps as I don’t need a read me, gitignore file or a licence but you may need these for projects later, particularly if you are sharing the repository with another user or having your work reviewed.
The gitignore file stops certain files being uploaded. Things like credentials or certain build files are best kept private and out of the repository.
Next we go back to Git Bash and set up our user credentials so we can push(copy) or work to GitHub. Using the details we provided for GitHub we add our details into Git Bash using the following commands. You will be asked to login using the web browser or the installed GitHub Desktop if you installed that earlier.
We then go back to GitHub and get the following screen after setting up our repository.
We have already initialized the folder and we don’t need a read me so we follow on by making our first commit. This is the initial save state which we can revert back to if we mess something up in future commits(saves).
Its always a good idea to add a comment when commiting changes. That way you can track what you changed, added or removed from the project. We use the -m (message) followed by our comment or message in quotes “message here”.
We then rename the branch to main. Branches can be created to seperate versions or parts of a project. In a game you may have levels seperated into branches. Each branch will maintain its own versions and history. These branches can be kept seperate while each is being developed and when they are ready, they can be merged together making them one large branch.
The next thing is setting the origin. This tells the local repository where the location is on the cloud to push or pull from.
Our repository is ready to go. My next post will include setting up Unity, creating a Unity project, creating a GitHub repository for that project and pushing the project to GitHub.