theme: ricetheme
New palette
New palette

Git Tutorial: Version Control Explained From Scratch

Git tutorial: stop guessing which file version is right with core commands, branches, remotes, mistake recovery, and a portable dotfiles setup you can reuse.

A developer views a git commit graph on a dark terminal, showing messy files transforming into organized tiles.

tl;dr the short answer

Git is a version control system that records a project’s history, letting you review changes and return to earlier versions. You choose changes to stage and commit, use branches to experiment safely, and connect to a remote to share or back up work. Small, clearly named commits make mistakes easier to undo, while a Git repository can keep files such as desktop settings portable across machines.

Ever saved a file as essay_final_v2_REAL.docx and wondered which version was the good one? Git ends that guessing game. It’s a version control system that records every change to a project, so you can browse past versions and return to any of them.

This tutorial walks through the mental model behind Git, its core commands, branching, remotes, and undoing mistakes. Then we’ll apply it to a Linux dotfiles repo, using SSH keys and a bare-repo setup to keep your desktop config safe and portable.

Why Git Matters in This Git Tutorial

Before we touch a command, here’s what Git does, how it differs from GitHub, and who this tutorial suits.

What Git does for your code

According to an IEEE Software article on Git, Git is a distributed version control system that tracks changes to code and lets you revert to earlier versions. Distributed means every copy of the project holds the full history.

Git is also the most widely used version control system (VCS).

Picture a Linux user tweaking their waybar config at midnight. One bad edit breaks the bar. With Git, they compare against the last working version and roll back, getting a working bar back without guessing.

How Git differs from GitHub

Many beginners mix these up, but they’re separate tools:

  • Git runs locally and tracks the history of a repository, a project folder Git watches.
  • GitHub hosts repositories online so you can share your work.
  • Git works without GitHub. You can use it alone on a dotfiles folder without making an account.
  • GitHub adds extras like pull requests (PRs), for proposing and discussing changes, and issues, for tracking bugs and tasks.

Is GitHub difficult to learn? Not really. Once you know Git, GitHub mostly adds a website for sharing your work. Git is the skill, and GitHub is the place you share it.

Who this suits and what you’ll need

This tutorial is written for:

  • Beginners with no version control experience
  • Anyone with basic terminal comfort, meaning you can open a shell and run commands
  • A computer with Git installed (your package manager can add it if it isn’t)

Is Git hard to learn? It has a reputation for being tricky, but it gets easier when you learn the mental model before the commands.

Git skills also come up in developer job interviews, so the effort pays off well beyond your dotfiles. It’s a skill that sticks.

Get Your Computer Ready for Git

Before you run your first Git command, you need Git itself, a GitHub account, and a terminal to type into. Let’s get all three ready.

How do I install Git on my computer?

Git is a program, so it has to be installed on your machine first. The method depends on your system:

  • Linux: use your distribution’s package manager: apt on Ubuntu, dnf on Fedora, or pacman on Arch.
  • macOS: choose Homebrew, the official installer, or Xcode, Apple’s developer toolkit.
  • Windows: run the executable installer.
  • Any system: download it from git-scm.com.

Think of a student on Ubuntu with a ten-year-old ThinkPad. One install step, and Git is ready for every exercise that follows.

If you’re asking how to install GitHub on the CLI, here’s the short answer: GitHub lives in your browser, while the GitHub command-line interface (CLI) lives in your terminal.

Install it separately, after Git, with the same package manager or installer you just used.

Set up your accounts and settings

Create a GitHub account and verify your email when prompted. Then run git config to set your name and email. Git attaches these to every commit you make, so your history shows who made each change. It takes a minute.

Choose the terminal you will use

Git runs from a terminal, and your choice depends on your system. On Windows, Command Prompt and PowerShell are built in, while Git Bash gives you a Linux-style shell. On macOS and Linux, the terminal app already on your system does the job.

Say you’re a dotfiles tinkerer on a Linux laptop. You can start practicing on your own config the moment Git is installed.

Flat illustration showing a developer using a laptop terminal for Git, with platform cards for Windows, macOS, and Linux above.

How Git Thinks About Your Project

Before you run a single command, it helps to know where Git keeps your work and how it remembers it.

The three places your files live

Git tracks your files in three places, and most commands move changes between them. Say you’re tidying your dotfiles on a fresh Arch install:

  • Working directory: the files you see and edit, like ~/.config/hypr/hyprland.conf after a keybind tweak.
  • Staging area (index): where you choose which changes go into the next snapshot, like a packing list.
  • Repository (.git folder): the hidden .git folder inside your project that stores every snapshot.

The usual flow is add then commit. git add moves changes into the staging area, and git commit turns them into a snapshot.

Git commits what you staged, not everything you changed, so you can commit the waybar fix without dragging in that half-finished kitty theme.

Why each commit is a snapshot

Think of each commit as a photo of your whole project at that moment, not a list of edits. Git labels every photo with a commit hash, a long string of letters and numbers that identifies that one snapshot.

You rarely need the full string. Git accepts a short hash, just the first few characters, as long as they’re unique in your repo, so git show a1b2c3d finds the same snapshot.

Each snapshot also gets a commit message, so pair the hash with a clear one. Picture a ricer who commits ‘tweak kitty padding’ today.

A few weeks later, when the terminal looks off after an update, scanning the log for that message points you straight at the change. Clear messages cost seconds. Vague ones cost hours.

What Are the Five Basic Git Commands?

Most daily Git work runs on five commands:

  • git init to start a repository
  • git add to stage changes
  • git commit to save them
  • git status to check where things stand
  • git log to review history

git clone and git stash are handy extras.

Start a new repo or clone one

Every project starts one of two ways. git init turns the current folder into a new repository, a folder Git tracks, and git clone URL copies an existing one, history included. Once you’ve cloned a project, you’ll want to know how to run GitHub code locally.

Don’t run git init in your home folder, or everything in there gets tracked. For dotfiles, use a bare repository instead: git init --bare $HOME/.dotfiles, plus a shell alias that tells Git to use that repo with your home folder as its work tree.

A hyprland user can version their keybinds and waybar config this way without putting a .git folder in ~.

Stage your changes and save commits

Git saves work in two steps. Staging is about choosing what goes in, and committing is about recording it. Use git add notes.md for one file or git add . for everything in the folder, then run git commit -m "Add waybar module".

Leave off -m and Git opens your text editor, where the first line becomes your summary.

Staging only the bar file lets a waybar tweaker commit that change alone, leaving their kitty theme for a separate commit. Run git status between steps to see what’s staged. Stage first, commit second. Files Git is not tracking yet show up as untracked files in that same status output.

Check your history and current status

git log shows where you’ve been, and git status shows where you are. Plain git log lists every commit with its hash, author, date, and message, while git log --oneline squeezes each one onto a single line.

Run git status after git init, git add, and git commit so you always know what Git just did.

Walk through your first session

Type these yourself rather than pasting them, since repetition is what makes them stick.

  1. mkdir notes && cd notes creates and enters a new folder.
  2. git init replies with Initialized empty Git repository in /home/you/notes/.git/.
  3. Create a file with echo "# Notes" > README.md, then run git status, which lists it as untracked.
  4. git add README.md and git commit -m "First commit" print something like [main (root-commit) 3f9c2a1] First commit.
  5. git log --oneline shows that first entry.

Your path, branch name, and hash will differ, and that’s fine.

Set unfinished changes aside with stash

Stash is for pausing work, not finishing it. git stash saves your uncommitted changes as a stash and returns your files to the last commit.

git stash pop restores the latest one, git stash list shows what’s saved, and git stash clear deletes them all, so check the list first.

Say you’re rewriting hyprland keybinds at 1am when a broken waybar module needs a fix. Stash the keybinds, fix the bar, then run git stash pop to get them back. Pause, don’t lose it.

A flat illustration of a dark terminal window with a git command, connected to a stash drawer containing code files and an amber tag.

Working on Branches and Merging Them

Branches let you test ideas without touching the setup that works. Here’s how to make one, merge it back, and name them well.

Make a branch and move between them

A branch is a separate line of work. Run git branch to list yours, then git checkout -b feature/waybar-colors to create one and switch to it in a single step. To return to an existing branch, run git checkout main, and Git swaps your files to match.

Isolation is what makes this safe. Picture a Linux user testing new waybar colors: on feature/waybar-colors, a bad guess can’t touch main, so the bar they rely on stays put.

Merge changes back and handle conflicts

When the tweak works, bring it home with a merge: switch to main and run git merge feature/waybar-colors. Then clean up with git branch -d feature/waybar-colors.

Sometimes both branches edit the same line. Git can’t pick a winner, so it stops with a merge conflict and marks both versions with <<<<<<<, =======, and >>>>>>> lines. Keep the version you want, delete the markers, then run git add and git commit.

Nothing is broken. You just need to choose.

How teams name and organize branches

  • dev holds work in progress
  • staging holds what you test before release
  • feature/ names like feature/waybar-colors show each branch’s purpose

Good naming is less about rules and more about clarity.

Your default branch may be called main or master. The name doesn’t change how Git works, so keep whatever your repo uses.

Gitflow adds long-lived branches for development, releases, and hotfixes. It suits teams with scheduled releases, but a personal dotfiles repo rarely needs it.

Working with Remotes and Teammates

Git on your own machine only tells half the story, so let’s bring in your teammates.

Connect to a remote and sync changes

A remote is a copy of your repository hosted elsewhere, like on GitHub. Link yours with git remote add origin <url>, where origin is the default name. Then git push sends your commits up, while git pull brings the latest changes down.

Set up Secure Shell (SSH) keys so pushes don’t ask for a password. Generate a pair with ssh-keygen, then add the public half to your GitHub account.

Picture a Linux user who keeps dotfiles on GitHub. One git push backs up a waybar tweak, and a fresh install can git pull the whole setup back.

Open pull requests and fork projects

A pull request asks the project to review and merge your branch. Push the branch, then open one on GitHub to show what’s different.

Code review happens before anything merges. Teammates read the diff, leave comments, and request changes first.

Forking is how you contribute to a project you don’t own. A fork is your own copy, so you can experiment without touching the original.

For example, a tmux tinkerer fixing a status-bar theme pushes a fix to their fork and opens a pull request back to the original. Once the maintainer merges it, the fix lands.

Team habits for contributing on GitHub

Collaboration workflows are the branching rules your team agrees on. A simple one keeps main stable and merges short-lived branches through pull requests.

Pull updates regularly. Run git pull before each session so you’re not building on stale code. Pull often, and conflicts stay small.

Contributing via GitHub means opening small pull requests with clear descriptions and answering review comments quickly. Reviewers will thank you.

Fixing Mistakes and Advanced Git Features

Git offers several ways back from mistakes, and we’ll cover traps too.

Undo changes with revert, reset, or reflog

Revert creates a new commit that undoes an earlier one, so it’s safe for shared work. Reset moves your branch pointer backward, and git reset --hard also throws away uncommitted edits.

The reflog records every place your HEAD (Git’s pointer to your current commit) has been, so it’s your safety net for resets.

Consider a Linux user who runs git reset --hard on their dotfiles and loses a tweaked tmux config. Recovery takes three steps:

  1. Run git reflog and find the entry just before the reset.
  2. Copy the short code at the start of that line.
  3. Run git branch tmux-rescue <hash> to save it on a new branch.

Your tweaked tmux config is safe again.

Diagram comparing git revert, reset hard, and reflog using commit pills and a tmux config card in a dark terminal theme.

Rebase, hooks, and other advanced options

Rebase replays your commits on top of another branch. Merge combines two histories with a merge commit. Merge keeps history as it happened, but rebase rewrites it, so save rebase for branches only you use.

Hooks are scripts in .git/hooks that run at events like committing. Git LFS (Large File Storage) keeps big files out of your history by storing small pointers. Submodules nest one repository inside another, pinned to a commit.

A basic dotfiles repo needs none of these yet.

Common traps that catch beginners

  • Detached HEAD. You’re on a specific commit, not a branch. Work made there can get lost, so run git switch -c <name> to put it on a branch.
  • Merge conflicts. Git marks clashing lines with <<<<<<<, =======, and >>>>>>>. Edit the file to keep what you want, then run git add and git commit.
  • Reading Git output hints. Git often prints the next command for you, so read it before you search.

Habits That Help and Mistakes to Avoid

Most Git frustration traces back to a few habits, good and bad. Here’s what to build early and which pitfalls to sidestep.

Habits worth building early

  • Commit often. A waybar tinkerer who commits after each working tweak can roll back one small step when tonight’s edit breaks the bar.
  • Clear commit messages. ‘fix bar padding’ tells future you exactly what changed. ‘stuff’ tells future you nothing.
  • Use branches liberally. Try a new hyprland keybind layout on a branch of your dotfiles. If it’s a mess, delete the branch, and your working setup never changed.
  • Use .gitignore. This file tells Git which files to skip, like cache folders and generated files.
  • Never commit secrets or tokens. Anything committed stays in your history even if a later commit deletes it, so keep API keys and SSH private keys out of the repo.

Mistakes new users often make

  • Learning GitHub before Git. GitHub is a website that hosts a repository for you, but Git is the tool doing the tracking on your machine. Learn the local commands first, and the website will make more sense.
  • Init in wrong folder. Running git init in your home directory makes Git track far more than you meant, so every file there shows up as untracked. Don’t start a repo until pwd confirms where you are.
  • Memorising without understanding. Copying commands from a forum works right up until something unexpected happens. You want to know why a command works, not just that it works. Understanding travels to the next problem. Memorised steps don’t.

Tools and Resources to Keep Learning

Once you’re comfortable with the commands, a few resources can help you keep growing. A common question is what the alternatives to Git are.

Other version control systems exist, but the tools below all work with Git repositories, so you can keep your repo and pick the interface you like best.

Graphical apps and editor support

If you’d rather click than type, a graphical client shows your history visually.

GitKraken, GitHub Desktop, and Sublime Merge all fit that description, and editors like VSCode and JetBrains include Git support so you can commit without leaving your editor.

Say you’re a Linux user who just tweaked a hyprland config and your bar vanished. A graphical diff shows the changed line at a glance. These tools show what Git does rather than replace it. The commands still matter.

Read the official docs and books

When you need a definitive answer, go to the source. The Git official documentation covers commands in depth, and the Pro Git book takes a slower, more narrative route through the same ideas.

For quick lookups, the command manual pages are one terminal command away: type man git-commit to read about a single command.

More tutorials, courses, and interview questions

Once the basics feel familiar, practice with guided material. Atlassian tutorials and the freeCodeCamp crash course teach the same core workflow in different styles, so if one doesn’t click, try the other.

For a hands-on walkthrough, try.github.io is worth a look. Finally, working through common Git interview questions helps you explain why a command works, not just which one to type.

Git makes more sense once you treat your project as a history of snapshots you can browse, branch, and rewind. The commands are simply the handles for working with that history.

Start small: initialize a repo, commit something real, then push it somewhere safe. Once your dotfiles live in a bare repo with working SSH keys, your desktop setup is ready to follow you from one machine to the next.

Commit often, experiment freely, and let your history do the remembering.

References

  1. Git | IEEE Software — dl.acm.org

Questions

What are five basic commands in Git?

Five basic Git commands are `git init` to create a repository, `git add` to stage changes, `git commit` to save them, `git status` to check the current state, and `git log` to review commit history.

What are the alternatives to Git?

Alternatives include other version control systems such as Subversion (SVN), Mercurial, and Perforce. Graphical clients such as GitKraken, GitHub Desktop, and Sublime Merge are alternatives to using Git in a terminal, but they still work with Git rather than replacing it.

How to install GitHub on CLI?

Install Git first, then install GitHub CLI (`gh`) separately using the package manager or installer for your operating system. For example, on macOS you can use Homebrew; on Windows, use a supported package manager such as WinGet; on Linux, follow the installation instructions for your distribution. Then run `gh auth login` to connect it to your GitHub account.

How to run a CLI command?

Open a terminal or command prompt, type the command, and press Enter. For example, run `git status` inside a Git repository to see its current state; commands may behave differently depending on your current folder and system.

How do I install Git on Windows?

Download and run the Git for Windows installer from git-scm.com, then follow its setup prompts. After installation, you can run Git from Command Prompt, PowerShell, or Git Bash.

Is GitHub difficult to learn?

No. GitHub is generally approachable once you understand the basics of Git; it mainly adds a website for sharing repositories and features such as pull requests and issues. Start with a few local Git commands, then learn how to share your work on GitHub.

Sources

  1. Git | IEEE Software, dl.acm.org