What Is Git And Why Should You Use It?

I’ve been wanting to make this tutorial for a long time to introduce others to the power of Git. For those who don’t know, Git is a version control system. What is that? Let me give an example.

Let say you are working on a project. Your main server handler works flawlessly, but you add a new feature. You’re worried it might break, but don’t want to create a whole duplicate of the script.

That’s where Git comes in. By simply staging the file and committing changes, you have effectively saved an encoded copy of the script in its current state. This encoded file is also able to be uploaded to GitHub, which you’ve probably heard of at some point. It’s an online database of remote repositories that people add their code to and let others review and improve it, or just keep a private area for version control.

After you write your important changes to the file, you stage and commit the file again. Now, there exists two copies of your script, not one. The original commit stores the first version of your script. The second commit stores the latest changes. Git allows you to roll back changes and recover old versions of your scripts if you don’t like how your changes turned out.

Now that we know what Git is, why should you be using it? As earlier mentioned, you are able to control the version of your scripts. In addition, you are able to directly upload your code to GitHub for remote storage.

Let’s say there’s a cool bit of code that you saw on a public repository on GitHub that you wanted to use. No problem! You can simply run git clone GITHUB_USERNAME/GITHUB_REPO_NAME (with real, off-Roblox git, use git clone https://github.com/GITHUB_USERNAME/GITHUB_REPO_NAME.git), and the entire repository will be loaded into a folder in the current directory.

How do you use it? Unfortunately, Roblox does not come with built-in Git support. However, there is a command-line plugin that I have developed with git support. You can follow the tutorial below to understand how to set up Git for Roblox and commit your first changes to a remote repository.

Tutorial
  1. First, download StudioCLI.
  2. Open a blank new Roblox project.
  3. Open the StudioCLI panel. I would recommend putting it on the bottom of the screen as shown:
Ahh - I forgot to update the version number with v1.3.0!
  1. If you’re a first-time user and want Git & GitHub support, do steps 5 and 6. If not, skip those.

  2. Create an account on github.com. Make sure to remember your username. After you’ve done that, type git config displayname <YOUR_USERNAME_HERE> -g . This will set your displayname for Git.

  3. Navigate to Sign in to GitHub · GitHub. Generate a new token, and allow the repo permission (refer to screenshot). Once you set an expiration date & copied the token, run git config token <THE_COPIED_TOKEN_HERE> -g . This will set your token globally across all of your places so you don’t have to do this again until the token expires.
    image

  4. Initialize a git repository. Run git init <YOUR_UNIQUE_GAME_NAME> --both for both a local and remote repo, or just git init <YOUR_UNIQUE_GAME_NAME> for a local repo. You must have a GitHub account and have done steps 5 & 6 at some point in time to have a remote repo! If you ever want to add a remote repo to an existing local repo, just run git init <YOUR_UNIQUE_GAME_NAME> --remote.

  5. Type cd workspace, hit enter, type touch, and hit enter. This will create a new script in the workspace. Type in any code you want into the script and exit it.

  6. Finally! Time to stage the file. Make sure your current directory is “game/Workspace” (if not, run cd workspace) and then run git add <NAME_OF_THE_SCRIPT_HERE> .

  7. Now that the file is staged, you can run git commit -m "commit message" . A commit message is a brief but descriptive message describing the changes.

  8. If you have a remote repo set up, you probably want to commit your first local commit to GitHub! To do this, run git push main. Let me explain this. In the last step, you commit changes to the “main” branch. So currently, your local branch is the “main” branch. When you ran git push main, you took the current branch’s last commit (which sound’s like a mouthful, but is really just that commit you made a minute ago), to the “main” branch on GitHub, since you ran “git push MAIN”. The “main” branch is mostly what you’ll use, but in the future, you may find a use for multiple branches. I won’t be going into the specifics, this step is long enough.

Congrats! You just commit your first commit and pushed it to GitHub! Welcome to the wonders of version control!

Thanks for reading! I hope you learned something new and go on to use Git as part of your projects on Roblox.

15 Likes

It’s worth noting that there are several projects that let you make Roblox projects on the filesystem, like Rojo, and with those you can use Git and any other normal programming tools, such as your favorite IDE.

2 Likes