DEV Community

Cover image for Git Commands for Beginners: A Complete Guide to Get You Started
Courage Labhani Paul
Courage Labhani Paul Subscriber

Posted on

Git Commands for Beginners: A Complete Guide to Get You Started

If you write code, sooner or later you will need Git. It is the version control system behind nearly every modern software project, and it's now used by roughly 94% of developers worldwide. That single number tells you most of what you need to know about why this guide exists: Git is not optional knowledge for a working developer, it is the baseline.

This article walks through the Git commands a beginner actually needs, in the order you will use them, with a real step-by-step project along the way. By the end, you will understand not just what to type, but why each command exists.

What Is Git and Why It Matters

Git is a distributed version control system. In plain terms, it keeps a complete history of every change made to a project, lets multiple people work on the same codebase without overwriting each other, and makes it possible to undo mistakes cleanly. Git's adoption has grown from about 87% of developers in 2016 to nearly 94% in 2025, and today it holds roughly 85% of the version control systems market. Alternatives exist, but Git has become the default.

It is worth clearing up a common beginner confusion early: Git and GitHub are not the same thing. Git is the tool that tracks changes on your machine. GitHub (along with GitLab and Bitbucket) is a website that hosts Git repositories online and adds collaboration features like pull requests and issue tracking. You can use Git without ever touching GitHub, but most teams use both together.

Without version control, a solo developer or small team often ends up with a folder full of files named project_final.js, project_final_v2.js, and project_final_v2_ACTUALLY_FINAL.js. Git replaces that chaos with a single tracked history you can search, compare, and roll back at any point.

Setting Up Git

Before running any commands, install Git for your operating system and confirm it worked:

git --version
Enter fullscreen mode Exit fullscreen mode

The syntax is identical whether you are on Windows, macOS, or Linux; only the terminal you use to run it changes. On macOS you will typically use the built-in Terminal app, on Windows you will use Git Bash or PowerShell, and on Linux you will use your default shell.

Once installed, tell Git who you are. This information gets attached to every commit you make:

git config --global user.name "Your Name"
git config --global user.email "you@example.com"
Enter fullscreen mode Exit fullscreen mode

This is a one-time setup per machine.

The Core Git Workflow

Before memorizing commands, it helps to understand the three-stage model Git is built around: the working directory, the staging area, and the repository.

Your working directory is the actual folder of files you are editing. The staging area is a holding zone where you place specific changes you intend to save. The repository is where those staged changes become permanent, recorded snapshots called commits. Almost every Git command moves a file between these three stages. Once this model clicks, the commands stop feeling arbitrary and start feeling like a logical sequence.

Basic Git Commands Every Beginner Needs

These five commands form the foundation of daily Git use.

git init creates a new, empty Git repository in your current folder, adding a hidden .git directory that stores all tracking data.

git status shows you the current state of your working directory and staging area: which files are modified, which are staged, and which are untracked. Beginners should run this constantly; it is the command that keeps you oriented.

git add <filename> moves a file's changes into the staging area, marking it for the next commit. Use git add . to stage everything in the current folder at once.

git commit -m "message" takes everything staged and saves it as a permanent snapshot in the repository's history. The message matters more than beginners expect. "fixed stuff" tells a future teammate, or a future version of you, nothing. "Fix null pointer error on empty cart checkout" tells them exactly what changed and why. As projects grow and more tools parse commit history automatically, clear messages become part of the project's documentation, not an afterthought.

git log displays the commit history: author, date, and message for each snapshot, letting you see exactly how the project evolved.

Step-by-Step: Your First Git Project

Here is the full sequence from nothing to a tracked project:

  1. Create a project folder and move into it: mkdir my-project && cd my-project
  2. Initialize Git: git init
  3. Create a file, for example README.md, and add some text to it
  4. Check what Git sees: git status (it will show the file as untracked)
  5. Stage the file: git add README.md
  6. Confirm it is staged: git status again (it now shows as staged)
  7. Commit it: git commit -m "Add initial README"
  8. Confirm the commit exists: git log

Repeat steps 3 through 7 every time you make a meaningful change. This loop, edit, stage, commit, is the daily rhythm of working with Git.

Pushing Code to a Remote Repository

Local commits only exist on your machine until you connect to a remote repository, typically hosted on GitHub or GitLab.

git remote add origin <url> links your local repository to a remote one, naming it origin by convention.

git push uploads your committed changes to that remote.

git pull downloads changes from the remote and merges them into your local branch in one step.

git fetch downloads changes from the remote without merging them, letting you review before integrating. This distinction trips up many beginners: fetch is the cautious version, pull is the direct one.

git clone <url> copies an entire existing remote repository, history included, onto your local machine, which is usually how you start contributing to a project someone else created.

Branching and Merging

A branch is an independent line of development. It lets you experiment or build a feature without touching the stable version of your project.

git branch <name> creates a new branch. git checkout <name> or the newer git switch <name> moves you onto it. git merge <name> brings the changes from that branch back into your current one.

Even working alone, branching is worth adopting early. Creating a feature/login-page branch to build a new feature, then merging it into main once it works, keeps your main line of code stable while you experiment freely elsewhere.

Common Beginner Mistakes

A few patterns cause a disproportionate share of beginner frustration:

  • Committing without staging first. git commit only saves what has been added with git add; skipping that step means nothing gets saved.
  • Skipping .gitignore. Without one, folders like node_modules or files containing secrets can get committed and pushed by accident.
  • Force-pushing without understanding the consequences. git push --force can overwrite a teammate's work; avoid it until you know exactly what it does.
  • Vague commit messages. They save seconds now and cost minutes later, every time someone has to reconstruct what actually changed.

Frequently Asked Questions

What are the most important Git commands for beginners?
init, clone, status, add, commit, push, pull, branch, checkout, merge, and log cover nearly all daily use.

What is the difference between Git and GitHub?
Git is the version control tool itself. GitHub is a platform that hosts Git repositories and adds collaboration features on top.

Do Git commands work the same way on Windows, macOS, and Linux?
Yes. The commands are identical across platforms; only the terminal used to run them differs.

What is the difference between git pull and git fetch?
fetch downloads changes without merging them. pull downloads and merges in one step.

How do I undo a mistake in Git?
Use git checkout -- <file> for unstaged changes, git reset before committing, or git revert after a commit has already been made.

Do I need to memorize every Git command?
No. A solid grasp of ten to twelve core commands, backed by a saved cheat sheet for the rest, covers nearly all beginner and intermediate work.

What's the best way to practice?
Build a disposable local project and run through init, add, commit, branch, and merge repeatedly until the sequence becomes automatic.

Conclusion

Git becomes intuitive once the underlying workflow, not just the command syntax, clicks into place. Start with the core loop of edit, stage, commit, add branching once that feels natural, and keep a cheat sheet nearby for anything you use less often. The fastest way to build fluency is to open a terminal and run the sequence above on a real project today.

Top comments (0)