Git Basics for Beginners: The Commands You Will Actually Use Daily

Git has a reputation problem. It is the tool every developer uses daily and almost every beginner fears. The fear is misplaced. Professionals run on a small core of commands, repeated thousands of times, and the exotic machinery exists for rare emergencies. These git basics for beginners cover the mental model that makes everything click, the eight commands of daily work, and the two ideas, branches and undo, that cause most of the confusion.

Illustrated diagram of a software engineering ecosystem, including source control with Git, collaboration, automation and cloud deployment

Three boxes, then eight commands

Forget the terminology for a moment and picture three boxes. The working directory is your desk: the files as they are right now. The staging area is a tray on the desk, holding the changes you have chosen for the next snapshot. The repository is the archive room, containing the permanent history of snapshots, called commits. Git’s whole job is moving work between these boxes. A commit is a photograph of the project at a given moment, labelled with a message explaining why it exists. Every command you will learn is one of those moves, and confusing error messages become readable once you ask which box they are talking about.

Install Git, then introduce yourself. The git config command sets your name and email, which are stamped on every commit you make. Use the email tied to your code-hosting account so the work is attributed correctly. Create a project folder and run git init to start tracking it, or use git clone followed by a repository’s address to copy an existing project, history included. That is the entire ceremony. Everything after this is the daily loop.

Three commands form the heartbeat of daily work. The git status command is your dashboard. Run it constantly, because it tells you what has changed, what is staged, and usually what to do next, in plain language beginners often underestimate. The git add command moves chosen changes to the staging tray. Add files by name rather than everything at once, especially early on, so each commit stays focused on one logical change. The git commit -m command takes the snapshot. Write messages as completions of the sentence “this commit will,” such as “fix login redirect” or “add password validation.” A history of such messages is useful documentation. A history of vague labels is an archaeological dig.

The same habit of saying one thing clearly is useful beyond Git. A short related guide on this site, What a Law Firm Website Needs to Be Clear, Credible and Easy to Contact, makes the same point about public pages: if a visitor cannot tell what to do next, the writing has failed.

Look before you commit, then share the work

The git log command shows the archive, newer entries first, with each commit showing its identifier, author and message. Adding oneline gives the compact view you will use most. The git diff command shows actual line-by-line changes, unstaged by default, or the tray contents before you commit when you use the staged flag. Reading a diff before committing is the habit that prevents classic accidents: a debug print left in, a password pasted into a config file, or an unrelated change smuggled into the wrong snapshot. Thirty seconds of diff reading is the cheapest code review in existence.

A remote is the shared copy of the archive, hosted on a service like GitHub, GitLab or a company server. The git push command sends your new snapshots up, while git pull brings everyone else’s work down and merges it into your desk. The rhythm of teamwork is to pull before you start, commit in small logical units, and push when a unit is complete. A clean push habit also matters beyond your own machine, because a push typically triggers automated testing and deployment.

Branches, undo, and the habits that prevent emergencies

A branch is simply a movable label pointing at a commit. Creating one with git branch or git switch -c gives you a parallel line of history where you can build a feature or attempt a fix without endangering the main line. When the work is proven, git merge folds it back in. Branches in Git are nearly free, so the usual pattern is a branch per task, however small. Merge conflicts are Git reporting that two lines changed the same place differently and a human must choose. They are routine rather than catastrophic, and they shrink when commits are small and branches are short-lived.

Beginners fear Git most when something goes wrong, so it helps to learn three safe ways to undo work. If you changed a file and want it back as it was, git restore discards desk changes, or unstages them when combined with the staged flag. If you committed too early, git reset –soft HEAD~1 un-commits while keeping every change staged and ready to recommit properly. If you need to reverse a commit that is already shared, git revert creates a new commit that undoes it while preserving history honestly. Dangerous commands like hard resets and force pushes exist, but you can work professionally for years touching them rarely. Until then, if an undo command sounds violent, ask before running it.

Commit early and often in small logical units, pull before starting, read the diff, write meaningful messages, and keep branches short. Also add a gitignore file so build output, dependencies and secrets never enter the archive. The absence of that setup causes real harm, because a committed password must be treated as a published one. Follow these habits and Git recedes into the background, noticed mainly on the day it saves your work.

Git basics for beginners boil down to three boxes, eight commands and a handful of habits: status, add, commit, log, diff, push, pull and branch. Learn the model and the commands stop being incantations. Start on your next small project, commit more often than feels necessary, and let the archive become the safety net it was designed to be.