Thursday 6 October 2016

Learning to GitHub: For Minecraft Modders

If you've been following the Minecraft modding community for some time you should have noticed that when some developers release their mods, alongside the download link to the release build; they also publish a link to an open-source repository for their mod. A large majority of these link will lead you to a website called GitHub, and at this point most of you with no prior experience in these matters will just rush the back button in your browser, thinking this might be too technical for you. Well it really isn't all that difficult to understand or even do, and with a bit of patience and an open mind, you too can learn how to GitHub. Let's get started whenever you're ready.

Before we talk about what GitHub can do for you, it's advantages and disadvantages and why you should use it when developing Minecraft mods, we first need to ask the question - what is GitHub? In order to answer this question we will take a look at the word "GitHub" and break it apart.

Note
If at any time you get confused, jump down to the section called "List of terms used on GitHub" to help you get a better starting grasp on what's being discussed.

Table of Contents


About Git and Version Control


The first word is Git. In a nutshell Git is a version control system that is used for software development. Your following question might be - what exactly is version control? Version control is a system that records changes to a file or set of files over time so that you can recall specific versions later. This means that every revision (change) your project has ever undergone will be recorded and ready to be used at any moment. Information about these revisions as well as the ability to revert your project to an earlier state of development is available to you.

Git stores your project in something called a repository, which in this instance is just a large storage of information. Most operations in Git only need local files and resources to operate – generally no information is needed from another computer on your network. This means that after you've set up your repository, you do not need to be connected to the internet to browse project history or make changes. In most cases you will want your repository hosted online. This is where a repository hosting service such as GitHub comes in. Hosting your repository online will make it available for other people to interact with. Other developers can clone or fork your repo, essentially making copies they themselves can work on.

In addition to making collaboration easier it also helps you back up your project as it is now stored on a server, so if you for some reason suffer an accidental systems crash that causes you to lose parts (if not all) of your project, you can feel better knowing that a copy of your project is safe and sound online. It works the other way around as well. Because Git is a"distributed" or "decentralized" version control system, every repository clone is really a full backup of all the data. Thus if any server dies, and these systems were collaborating via it, any of the client repositories can be copied back up to the server to restore it. You can read more about version control here.

To understand Git, it's important to understand how it handles data. Once you've made some changes to your project you want to save them. To do that in Git, you need to commit them. Committing is the process of adding your changes to the history of your repository and assigning a commit name to it. Before you make a commit you have to choose which changes you want to include in it. Ideally each commit should reflect an accomplished task, so you should choose to include only those changes that are relevant to that task, followed by a fitting description. The way I understand it, every commit is a pointer to a snapshot which is a read-only copy of the data set frozen at a point in time. Each snapshot is a locked point in time we can observe or choose to return to. This section of the Git documentation explains it in more detail. You will see how Git uses the benefits of snapshots in the following section.

Another powerful feature of Git is called branching - a process of diverging from the main line of development and continuing to do work without messing with that main line of development. You can visualise this concept as a flowing river (main branch) that splits into smaller rivers without changing it's direction or intensity. These new smaller rivers now contain all the contents of the water before branching as well as new elements inherited from their own beds. The main purpose of branching is code isolation that aims to isolate a development effort such as a bug fix, new feature or something else. They are also useful for staging branches (preparations for new project releases) and private branches (small tasks and work in progress code). Read more about branches here. If you want to know when to use them, read this.

What exactly is GitHub?


In addition to what I've mentioned earlier about GitHub being a web-based Git repository hosting service, it's essentially a code sharing and publishing service, as well as a social networking site for programmers. It includes collaboration features such as bug tracking, feature requests, task management, and wikis for every project. GitHub is mostly used for code but can be used for any other project type that can benefit from revision control and online collaboration.

One of the most interesting features of GitHub is forking. If you want to contribute to an existing project to which you don’t have write access (unable to push commits directly), you can “fork” the project. What this means is that GitHub will make a copy of the project that is entirely yours; it lives in your user’s namespace, and you can push to it. There are two reasons you might decide to fork a project: you want to contribute to the original project, but lack the write privileges to do so, or you wish to develop the project in your own vision. Once you've forked the project you can start making changes to it. If the reason you forked the project is collaboration then you will at some point in time want to tell others about the changes you've made, and possibly even see your changes accepted and merged with the original project. We can do this with a feature called pull request. Read more about them here.

As mentioned above, GitHub is a social networking site as much as it is a repository hosting service. It's a social network that has completely changed the way we work. Having started as a developer’s collaborative platform, GitHub is now the largest online storage space of collaborative works that exists in the world. I will use the words of  How-To Geek to better explain the importance of this aspect:

The social networking aspect of GitHub is probably its most powerful feature, and is what allows projects to grow more than anything else. Each user on GitHub has their own profile, which can act like a resume of sorts, showing your past work and contributions to other projects via pull requests.

Project revisions are able to be discussed publicly, so a mass of experts can contribute knowledge and collaborate to advance a project forward. Before the advent of GitHub, developers interested in contributing to a project would usually need to find some means of contacting the authors, probably by email, and then have to convince them that their contribution is legit and they can be trusted.

It's important to note that you are in no way forced to use GitHub if you want to collaborate on a project over the internet using version control system. You are free to choose other services, the most prominent being BitBucket that allows unlimited public and private repositories, a service that GitHub unfortunately does not provide. The most important reason why you should choose GitHub for hosting your open-source Minecraft mod project is the ability to easily network with other Minecraft mod developers. There is also the full compatibility with Git and numerous other reasons, but the former one remains most important.

List of terms used on GitHub


Here is a quick list of words you will frequently see on GitHub,  followed by an explanation. This list was taken from a great user-friendly tutorial I found online called GitHub For Beginners: Don't Get Scared, Get Started.

Command Line: The computer program we use to input Git commands. On a Mac, it’s called Terminal. On a PC, it’s a non-native program that you download when you download Git for the first time (we’ll do that in the next section). In both cases, you type text-based commands, known as prompts, into the screen, instead of using a mouse.

Repository: A directory or storage space where your projects can live. Sometimes GitHub users shorten this to “repo.” It can be local to a folder on your computer, or it can be a storage space on GitHub or another online host. You can keep code files, text files, image files, you name it, inside a repository.

Version Control: Basically, the purpose Git was designed to serve. When you have a Microsoft Word file, you either overwrite every saved file with a new save, or you save multiple versions. With Git, you don’t have to. It keeps “snapshots” of every point in time in the project’s history, so you can never lose or overwrite it.

Commit: This is the command that gives Git its power. When you commit, you are taking a “snapshot” of your repository at that point in time, giving you a checkpoint to which you can re-evaluate or restore your project to any previous state.

Branch: How do multiple people work on a project at the same time without Git getting them confused? Usually, they “branch off” of the main project with their own versions full of changes they themselves have made. After they’re done, it’s time to “merge” that branch back with the “master,” the main directory of the project.

Use this list as simplified references to what these terms mean. They are not meant to complement your lack of knowledge or understanding, but help ease your learning curve.

Setting up Git


Now that you are introduced to the basics of what's what, it's time to actually set things up. GitHub has a very simple article on how to do this here. I will try to condense and focus what is written there to the best of my abilities. I will also assume that you have no prior experience with Git and currently feel a bit uncomfortable using the command line, so we will use GitHub's official desktop client

You should download and install the client now (note that the client will automatically install Git and keep it up-to-date for you, so no need to worry about that). After the client is installed we will proceed with setting it up. If you still do not have a GitHub account, you should head to GitHub's website and create a free account, you will need that to authenticate. The process is very straightforward; we only need to register our name and email so we get proper credits for our commits, and authenticate our client to GitHub so we are not asked for our username and password every time we try to push or pull our changes. 

Open your client, find and click the cog symbol in the upper-right corner of the app. Choose "Options" From the available context options that have appeared. Enter your name and email under Configure git.

Configuring Git from the GitHub Desktop client

Note
it doesn't matter if the name is your real name, your nickname or something else, Git only wants to know who to credit for the commits pushed from this client

Next up, we should authenticate to GitHub. In the client options find Accounts and choose Add account. Now simply enter your GitHub username and password in the appropriate fields. Don't worry, your information should be safe, unless the information is somehow sniffed out by a world class hacker, in that case you're screwed.

Authenticating to GitHub from the GitHub Desktop client.

Celebrate


Congratulations, you've successfully set up Git and GitHub! You should take a moment to pat yourself on the back and take a few minutes to relax. What's up next? That's entirely up to you. If you already have a mod project you're working on, you should create a new repo, clone it and dump your mod files there. If you are interested in contributing to other mods WIP mods out there, take a look at this list on MinecraftForum. Once you've found an open source mod in development you like that has a repository on GitHub, fork the repo and start contributing. And last but not least, if you have no idea what to do, I suggest reading a tutorial I wrote about Getting Started With Minecraft Modding.

Thank you for taking the time to read this. I hope it helps you out on becoming the best modder you can be. If you have the time, be sure to leave a comment and say a few words. As always, don't feel shy to share this article with people you think might benefit from it, and keep in mind that more articles are on their way. In the meantime, happy modding everyone!

No comments:

Post a Comment