Lesson 5 of 8
Git from zero: commits, diffs, branches, undo
Learn Git from zero with a Roblox config file: init, status, add, commit, log, diff, branches, merges, .gitignore, and how to undo mistakes safely.
By the end you can
- Turn a folder into a Git repository and record commits with status, add, commit, log and diff.
- Use branches to try a change safely, then merge it or throw it away.
- Keep files out of Git with .gitignore and undo mistakes with restore and revert without losing work.
Before this: The terminal from zero (PowerShell and macOS Terminal), A code editor from zero: VS Code and Cursor
1What did I change?
On Monday you set WRENCH_RANGE = 30 to test something in Beacon Yard. On Wednesday the drone fights feel wrong: you can hit drones from across the yard. You have touched six files since Monday and you cannot remember which numbers you changed or what they used to be.
Every developer has lived this. The fix is a tool that remembers every version of every file you choose to save, tells you exactly what changed between any two of them, and lets you go back. That tool is GitGitA version control tool that records every change to a folder of files.Think of it as save points, with branches as parallel save files., and every professional Roblox studio uses it or something very like it.
Which problem is Git built to solve?
Answer
Remembering versions of your files, showing what changed, and getting old versions back. Git is version control: a history of your files that you add to on purpose. Uploading happens elsewhere, and error checks come from the editor and tests.
Open this step in lesson mode · Link to this step · This confused me
2Install Git and introduce yourself
Windows. Download Git for Windows from the official site and run the installer 1. The defaults are fine, with one change: on the page that asks for Git's default editor, choose Visual Studio Code. The installer also adds Git Bash and the Git Credential Manager, which the GitHub lesson uses.
macOS. Run xcode-select --install in Terminal, or accept the prompt that appeared when you typed git in the terminal lesson. Apple's command line tools include Git 2. Homebrew users can run brew install git instead.
Git stamps every save point with a name and an email. Tell it yours once, in a new terminal:
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
These become public when you share your work on GitHub. If you would rather keep your email private, GitHub gives you a noreply address you can use here instead 3.
Build along
Install Git, open a new terminal, set your name and email, then run
git --versionandgit config --global user.name.You should see git --version prints git version 2.x, and git config --global user.name prints the name you set.
Open this step in lesson mode · Link to this step · This confused me
3Save points
| In the picture | In Roblox |
|---|---|
| A save point | A commit: a snapshot of every tracked file |
| Loading an old save | Checking out an earlier commit or milestone tag |
| A second save file | A branch where you try something without touching main |
You already know how this works from video games. Before a hard boss you save. If the fight goes badly you load the save and try again. A good game keeps a list of saves with the time and place of each, so you can go back further than the last one.
Git gives your project save points:
- A repositoryRepositoryA project folder that Git is watching, together with its history.Think of it as the game's save folder, with every save inside it. (or repo) is a project folder that Git is watching, together with its list of saves.
- A commitCommitOne save point in Git: a snapshot of chosen files with a message, an author and a time.Think of it as a save point you create on purpose, with a label. is one save point: a snapshot of the files you chose, a message saying what changed, your name and the time, and a short id like
5b92ddb. - The logLogThe list of commits in a repository, newest first.Think of it as the list of saves in your game's load screen. is the list of saves, newest first.
Unlike most games, Git never saves automatically. You decide when a moment is worth keeping, and you write the label yourself.
Think of it as Save points and a parallel save file
Match each Git word to its video game equivalent.
Answer
Repository: The game's save folder, with every save in it; Commit: One save point; Commit message: The label you type on a save; git log: The list of saves, newest first. A commit is a save point you create on purpose, with a label. The repository holds all of them.
Open this step in lesson mode · Link to this step · This confused me
4Start a repository
Use the practice folder from the editor lesson, with its Config.luau. Open it in VS Code and open the integrated terminal (Ctrl + `). Then run:
git init -b main
Git replies Initialized empty Git repository in .../practice/.git/. It has created a hidden folder called .git, and that folder is the repository: every save point lives inside it. The -b main names the first branchBranchA named line of commits that you can work on without touching main.Think of it as a second save file where you try something risky. main; branches come later in this lesson.
Never edit files inside .git by hand. Deleting that folder deletes the whole history.
Build along
Code/practice/.git
Run
git init -b maininCode/practice, then list hidden files to see.git.You should see ls -a (macOS) or ls -Force (PowerShell) lists .git next to Config.luau.
Open this step in lesson mode · Link to this step · This confused me
5Ask Git what it sees
git status is the command you will type most. It never changes anything; it just reports. Right now it says:
On branch main
No commits yet
Untracked files:
(use "git add <file>..." to include in what will be committed)
Config.luau
nothing added to commit but untracked files present (use "git add" to track)
Untracked means Git sees the file but has never saved it. Git is polite: the lines in brackets tell you which command to run next.
Git thinks in three places, and status tells you what is in each:

Edit in the working folder, choose what goes in the next save with add, and save it with commit.
git status lists Config.luau under 'Untracked files'. What does that mean?
Answer
Git can see the file but has never saved it in a commit. Untracked files exist in the working folder but are not in any commit yet. git add starts tracking them.
Open this step in lesson mode · Link to this step · This confused me
6Your first commit
Two commands make a save point. git add puts a file into the staging area, and git commit saves everything staged:
git add Config.luau
git commit -m "Add Beacon Yard config"
Git answers:
[main (root-commit) 5b92ddb] Add Beacon Yard config
1 file changed, 11 insertions(+)
create mode 100644 Config.luau
5b92ddb is the start of the commit's id; yours will be different, because the id is computed from the contents, your name and the time. -m gives the message on the command line. Without -m, Git opens your editor for the message.
On Windows you may also see "LF will be replaced by CRLF the next time Git touches it". That is Git handling Windows line endings for you, and it is harmless.
Build along
Code/practice/Config.luau
Run the two commands, then
git statusagain.You should see Git prints a line starting [main (root-commit) followed by an id and your message, and git status then says 'nothing to commit, working tree clean'.
Open this step in lesson mode · Link to this step · This confused me
7See exactly what changed
Now change something. In VS Code set COIN_VALUE = 10 and save. Then run git diff:
diff --git a/Config.luau b/Config.luau
index 6a22632..9bc0493 100644
--- a/Config.luau
+++ b/Config.luau
@@ -1,7 +1,7 @@
local Config = {
ROUND_SECONDS = 40,
COOLDOWN_SECONDS = 8,
- COIN_VALUE = 5,
+ COIN_VALUE = 10,
COIN_RESPAWN_SECONDS = 4,
WRENCH_DAMAGE = 34,
WRENCH_RANGE = 14,
A diffDiffA view of what changed between two versions of a file.Think of it as a marked-up page: red lines were removed, green lines were added. shows what changed. Lines starting with - were removed and lines starting with + were added, so a changed line appears as one of each. Unchanged lines around them give context. The @@ line says where in the file this is.
This is the answer to Wednesday's mystery: git diff shows every number you have changed since your last commit and not yet staged, in every tracked file. Once you git add a change, plain git diff stops showing it (git diff --staged does), and a brand-new file never appears until you add it.
VS Code shows the same thing graphically. Open the Source Control view (the branching icon, or Ctrl + Shift + G on Windows and Control + Shift + G on macOS, not Command) and click the file.

Select a numbered pin, or a row below, to read what it marks.
Source Control shows the same diff as git diff, side by side.
A diff shows '- WRENCH_RANGE = 14,' followed by '+ WRENCH_RANGE = 30,'. What happened?
Answer
WRENCH_RANGE was changed from 14 to 30. Minus is the old version and plus is the new one. Together they show one line changed from 14 to 30.
Open this step in lesson mode · Link to this step · This confused me
8The list of saves
Commit the change, then look at the history:
git commit -am "Double the coin value for testing"
git log --oneline
09fc183 (HEAD -> main) Double the coin value for testing
5b92ddb Add Beacon Yard config
The (HEAD -> main) label shows which branch you are standing on and where it points. Every other branch would appear in the same brackets, on its own latest commit.
-a adds every already-tracked file that changed, so commit -am stages and commits in one go. It never picks up brand-new files; those always need git add first.
Plain git log, without --oneline, also shows the author and date of each commit. Press q to leave it when it fills the screen.
The sandbox below draws the same history as a graph. Make three commits there and watch the line of save points grow.
The Git graph

Build along
Optional, for real: In your
practicerepository, change a different value inConfig.luauand commit it, three times, each with a clear message. Then rungit log --oneline.You should see git log --oneline lists your commits, newest first, with your three messages at the top.
Open this step in lesson mode · Link to this step · This confused me
9Write messages your future self can use
A message is the label on a save point. In three months, "stuff" and "fix" tell you nothing. A good message says what changed, in the imperative mood, as if finishing the sentence "This commit will...":
Double the coin value for testingMake rounds 60 secondsStop the drone hitting players through walls
Keep the first line under about 60 characters. Make one commit per idea: if your message needs "and", it is often two commits.
Which commit message is most useful?
Answer
Reduce wrench range from 30 to 14 studs. It says what changed and could be found again by searching the log for 'wrench'. The others need you to read the diff to understand them.
Open this step in lesson mode · Link to this step · This confused me
10A parallel save file
Good place for a break. Your answers and progress are saved in this browser, so you can stop here and come back to this step. Tick what you can do now; if something is shaky, go back one step first.
Checkpoint
- I have a practice repository with at least one commit
- I can read a diff, with - for removed lines and + for added lines
- I can write a commit message that says what changed
What if you want to try longer rounds without risking the version that works? In a game you would copy your save into a new save slot and play on from there. If it goes badly, you go back to the original slot, untouched.
That is a branch. main is the slot you have been using. Make a new one and switch to it:
git switch -c longer-rounds
-c means create. Change ROUND_SECONDS to 60, save, and commit. Then switch back:
git switch main
Look at Config.luau in VS Code: ROUND_SECONDS is back to 40. Git swapped the files in your folder to match the slot you switched to. Your 60-second commit is safe on longer-rounds.
Both sidesRemember: Git commits and branches is save points and a parallel save file.
The Git graph

Build along
Optional, for real: In your
practicerepository, createlonger-rounds, changeROUND_SECONDSto 60 and commit it, then switch back to main and openConfig.luau.You should see Config.luau on main says ROUND_SECONDS = 40 again, and git branch lists both main and longer-rounds.
Open this step in lesson mode · Link to this step · This confused me
11Bring a branch back
The longer rounds felt good. To bring that work into main, stand on main and merge the branch:
git switch main
git merge longer-rounds
Updating 09fc183..d91ed16
Fast-forward
Config.luau | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Fast-forward means main had not moved since the branch started, so Git simply slid main forward to the branch's latest commit. When both branches have new commits, Git makes a merge commit that joins the two lines of history.
If the experiment had failed, you would just stay on main and delete the branch with git branch -D longer-rounds. Nothing on main would ever have changed. Use the capital -D here: a lowercase -d refuses to delete a branch that was never merged, which is what a failed experiment is. The capital letter means "delete it anyway", so the commits that only lived on that branch are thrown away. Check the branch name before you press Enter.
You want the work from longer-rounds in main. Which is right?
Answer
On main, run git merge longer-rounds. Merge pulls the named branch into the one you are standing on. To change main, stand on main.
Open this step in lesson mode · Link to this step · This confused me
12Where save points break: conflicts
Here the video game picture stops working. Games never ask you to combine two save files. Git does it all the time, and usually Git combines them on its own. The exception is when both branches changed the same line in different ways. Git cannot know which you meant, so it stops and asks:
Auto-merging Config.luau
CONFLICT (content): Merge conflict in Config.luau
Automatic merge failed; fix conflicts and then commit the result.
Inside the file, Git marks both versions:
<<<<<<< HEAD
WRENCH_RANGE = 10,
=======
WRENCH_RANGE = 20,
>>>>>>> long-wrench
The top half is the branch you are on (HEAD), and the bottom half is the branch you are merging in. To resolve it, edit the file so it holds the line you want, delete all three marker lines, save, then git add Config.luau and git commit. To back out completely, run git merge --abort.
Where does it break?“Save points and a parallel save file” is a good picture of git commits and branches. Where does it stop being true?
It breaks here. Two save files can never be combined in a game, but Git merges branches line by line; and when the file is binary, such as a place file, Git cannot merge it at all and one version must win.
The true model. Git tracks text files as a history of commits. Branches diverge and merge; conflicting lines need a person to decide. Binary files have no lines, so teams keep code and the project file in Git and build the place from them.
You and a teammate settle on 14 studs, the original value. Which text should replace the whole conflicted block when you save?
<<<<<<< HEAD
WRENCH_RANGE = 10,
=======
WRENCH_RANGE = 20,
>>>>>>> long-wrench
Answer
WRENCH_RANGE = 14,. All three marker lines go, and exactly one WRENCH_RANGE line stays. A resolution can be either side, both or neither: here it is neither. Then git add and git commit.
Open this step in lesson mode · Link to this step · This confused me
13Where save points break again: place files
The second break matters a lot for Roblox. Git's diffs and merges work line by line on text. A Roblox place saved as .rbxl is a binary file: bytes that only Studio understands. Git can store it, but git diff can only say "binary files differ", and two people's changes to one .rbxl can never be merged. One version wins and the other is lost.
That is why Beacon Yard keeps its code as .luau text files in Git, has its yard built by code when the server starts, and treats the place file as something tools generate, never something to commit by hand. Rojo, which you meet in the setup lesson, builds the place from the text files.
Two people each change BeaconYard.rbxl on their own branches and merge. What happens?
Answer
Git cannot merge a binary file, so one version must be chosen and the other's changes are lost. Line-by-line merging needs text. This is why Beacon Yard keeps its source as .luau files and builds the place from them.
Open this step in lesson mode · Link to this step · This confused me
14Files Git should ignore
Some files should never be committed: built outputs that tools regenerate, files your editor or operating system leaves around, and anything private. A file called .gitignore.gitignoreA file that lists name patterns for Git to leave out of commits.Think of it as a 'do not pack' list for your save folder. in the repository lists name patterns for Git to ignore 4. Here is the start of Beacon Yard's:
build/
*.rbxl
*.rbxlx
*.rbxl.lock
sourcemap.json
Read it as a list of patterns. build/ ignores the whole build folder. *.rbxl ignores every file ending in .rbxl, because * matches any name. Ignored files do not show up in git status at all.
Later in the course you will create Ids.local.luau for your own Roblox asset ids. It is git-ignored too, so your ids never end up in a public repository.
Using the patterns above, which files would Git ignore?
Answer
build/BeaconYard.rbxlx; test-place.rbxl; sourcemap.json. build/ covers everything in build, *.rbxl matches test-place.rbxl, and sourcemap.json is listed by name. Source files and the README are tracked.
Open this step in lesson mode · Link to this step · This confused me
15Undo things safely
Most of Git's power is getting things back. Pick the command for the situation:
| Situation | Command | Safe? |
|---|---|---|
| I edited a file and want the last committed version back | git restore Config.luau | Throws away those uncommitted edits for good |
| I staged a file by mistake | git restore --staged Config.luau | Yes: the edits stay in your folder |
| My last commit's message is wrong, and I have not shared it | git commit --amend -m "Better message" | Yes, before you push |
| A commit was a mistake, and it is already shared | git revert 09fc183 | Yes: it adds a new commit that undoes the old one |
git revert is the safest undo once others have your history, because it never rewrites the past 5. git restore is for work that was never committed 6.
Be careful with two commands you will see recommended online: git reset --hard and git push --force. Both can permanently destroy work. If a tutorial or an AI suggests one, stop and make sure you understand what it will throw away first.
Match each situation to the right command.
Answer
Throw away unsaved-to-Git edits in one file: git restore Config.luau; Unstage a file but keep the edits: git restore --staged Config.luau; Undo a commit that is already on GitHub: git revert <id>; Fix the message of the last, unshared commit: git commit --amend. Restore works on uncommitted changes. Revert adds a new commit that undoes an old one. Amend rewrites only the last commit, so use it before pushing.
Open this step in lesson mode · Link to this step · This confused me
16Command line, VS Code or GitHub Desktop?
Everything in this lesson can also be done by clicking.
Ways to use Git
| Option | What it is | When pros pick it | Trade-offs |
|---|---|---|---|
| The command line | Git itself, typed in the terminal (what this course shows first). | Always available. Error messages and online help are written in terms of these commands, and CI runs them too. | You have to remember the commands, and the output can look dense at first. |
| VS Code Source Control | A panel built into VS Code (Ctrl + Shift + G on Windows, Control + Shift + G on macOS) that stages, commits, shows diffs side by side and switches branches from the status bar. | Reviewing a diff before you commit, and everyday commits without leaving the editor. | It hides the commands, so you still need the terminal when something goes wrong. |
| GitHub Desktop | A free app from GitHub for Windows and macOS that does the everyday commands with buttons and handles signing in to GitHub for you. | The terminal still feels uncomfortable. | Fewer commands are available, and you cannot copy a command from a tutorial into it. |
Use whichever you like day to day, but know the commands. When something goes wrong, the fix will be described in commands.
You commit with GitHub Desktop. A friend runs git log on the same repository. What do they see?
Answer
Your commit, like any other; Desktop uses Git underneath. Every Git tool reads and writes the same .git folder. The tool you use does not change the history.
Open this step in lesson mode · Link to this step · This confused me
17Cheat sheet
Reference Git cheat sheet
| Task | Command |
|---|---|
| Start a repository | git init -b main |
| What is going on? | git status |
| Stage a file / everything | git add Config.luau / git add . |
| Save a commit | git commit -m "Message" |
| Stage tracked changes and commit | git commit -am "Message" |
| History | git log --oneline (--graph --all to see branches) |
| Unstaged / staged changes | git diff / git diff --staged |
| New branch and switch to it | git switch -c name |
| Switch branch | git switch name |
| Merge a branch into the current one | git merge name |
| Abandon a conflicted merge | git merge --abort |
| Discard uncommitted edits to a file | git restore file |
| Undo a shared commit | git revert id |
Put the everyday loop in order.
Answer
1. Edit and save a file 2. git status and git diff to check 3. git add the files for this change 4. git commit -m with a clear message. Edit, check what changed, stage what belongs together, then commit. git status between any two steps never hurts.
Open this step in lesson mode · Link to this step · This confused me
18Challenges
Level 2, Builder
Challenge
Merge two branches that disagree, and settle the conflict yourself.
- Start from
- The git-graph sandbox, preset two-branches.
Done means
- main contains the work from long-wrench.
- The conflict is resolved with WRENCH_RANGE = 14 and no marker lines remain.
- The merge is committed, and git log --oneline --graph shows two lines of history joining.
Hints
- Stand on main before you merge.
- After editing the file, git add it before git commit.
Solution
git switch main; git merge long-wrench; edit Config.luau to keep WRENCH_RANGE = 14 and delete the three marker lines; git add Config.luau; git commit -m 'Merge long-wrench, keep 14 studs'
The Git graph

Level 1, Apprentice
Challenge
Do the whole branch-and-merge loop in a real repository of your own.
- Start from
- Your real Code/practice repository with two commits.
Done means
- You made a branch, committed one change on it, and merged it into main.
- git log --oneline shows at least four commits with clear imperative messages.
- git status says the working tree is clean.
Hints
- git switch -c, edit, commit -am, switch main, merge.
Open this step in lesson mode · Link to this step · This confused me
19Recap
Recap
- A commit is a save point you make on purpose: git add chooses what goes in, git commit saves it, and git log and git diff show history and changes.
- A branch is a parallel save slot. Try changes there and merge them into main from main. Conflicts happen when both sides changed the same line, and you resolve them by editing.
- Git merges text, not binary place files, so Beacon Yard keeps code as .luau and ignores builds. Undo with restore for uncommitted work and revert for shared commits; be wary of reset --hard and push --force.
Git commits and branches is save points and a parallel save file, until two save files can never be combined in a game, but Git merges branches line by line; and when the file is binary, such as a place file, Git cannot merge it at all and one version must win.
Queued for review
Open this step in lesson mode · Link to this step · This confused me