Git can look intimidating because it has well over a hundred commands, but daily work uses a surprisingly small core. Most developers, on most days, run the same fifteen commands in a loop: check what changed, stage it, commit it, share it, and occasionally look at history or switch branches. Learn that loop properly and you can handle the normal flow of a project on your own. The advanced commands still matter when something goes wrong, and we cover recovery separately in our guide to undoing changes in Git, but the fifteen here are the foundation everything else builds on.
Each command below follows the same format: the command itself, a plain explanation of what it does, and the situation where you reach for it. Commands are shown as you would type them in a terminal. If you are new to the terminal itself, our roundup of Linux commands for developers covers the navigation basics that Git work assumes.
Setting Up: init and clone
Every Git workflow starts in one of two ways. Either you create a brand new repository in an existing folder, or you copy a repository that already exists somewhere else. Two different commands handle those two jobs, and confusing them is a common beginner stumble.
git init git clone https://github.com/example/project.git
The first line, git init, turns the current folder into a Git repository by creating a hidden git directory inside it that will store the entire history. Nothing is uploaded anywhere and no files are changed; Git simply starts watching the folder from that moment. You run it once per project, at the very beginning. The second line, git clone, does the opposite job: it downloads a complete copy of an existing repository from a remote address, including its full history, and places it in a new folder named after the project. When you join a team or start work on any existing codebase, clone is almost always your first command. Never run init inside a cloned project, because it already is a repository.
Checking State: status and diff
Before you save or share anything, you need to know what state your files are in. Git divides files into rough groups: untracked files it has never seen, modified files that differ from the last commit, and staged files that are queued for the next commit. Two commands report on that state, and experienced developers run them constantly, almost as a reflex.
git status git diff git diff --staged
The status command is the dashboard. It lists which branch you are on, which files have changed, which are staged, and often a hint about what to do next. Run it before every commit and whenever you feel unsure where you stand; it changes nothing and is always safe. The plain diff command shows the exact line-by-line changes in files you have modified but not yet staged, so you can review your own work before saving it. Adding the staged flag shows the same line-by-line view for files that are already staged, which is the final check before committing. Reading your diff before you commit catches debug lines, accidental deletions, and half-finished edits while they are still free to fix.
Saving Work: add and commit
Committing in Git is a two-step process, and understanding the two steps explains most of Git behaviour. First you stage changes with add, choosing exactly what goes into the next snapshot. Then you commit, which records that snapshot permanently in the history with a message describing it. The staging step feels like extra work at first, but it is what lets you split a messy afternoon of edits into two or three clean, logical commits.
git add index.html git add . git commit -m "Add contact form to homepage"
The first add line stages one named file and nothing else, which is the precise option when you have changed several files but only some belong together. The second line stages everything that changed in the project; it is fast and fine for simple saves, but worth a status check first so you do not sweep in a file you meant to keep separate. The commit line creates the snapshot from whatever is staged, and the m flag attaches the message in quotes. Write messages that complete the sentence this commit will, in short plain language: fix login redirect, add contact form, remove unused styles. A future reader, often you in three months, scans messages to find when something changed, and vague messages like update or changes make that search useless. Commit small and commit often; small commits are easier to review, easier to undo, and easier to understand than one giant end-of-week snapshot.
Sharing Work: push, pull, and fetch
Commits live on your machine until you share them. The remote repository, usually on a hosting service, is the shared copy your team reads from and writes to. Three commands move history between your copy and the remote, and keeping their roles straight prevents most sync confusion.
git push origin main git pull git fetch
Push uploads your new commits to the remote. The word origin is the standard nickname for the main remote, and main is the branch being sent. You push when your work is committed and ready for others to see or build on. Pull does the reverse journey in one step: it downloads new commits from the remote and merges them into your current branch. Run it when you start work, especially in a team, so you build on the latest code rather than yesterday copy. Fetch is the cautious half of pull. It downloads the new commits but does not merge them, so you can inspect what arrived before deciding how to combine it with your work. When a pull surprises you with conflicts, it is usually because fetched changes and your changes touched the same lines; fetching first and looking keeps that surprise under your control. Our branching workflow guide shows how push and pull fit into a full feature branch routine.
Moving Around: branch and checkout or switch
Branches let you develop a feature or a fix in isolation without disturbing the stable code. A branch is simply a movable pointer to a commit, which makes creating one instant and cheap. Two of the fifteen commands manage them day to day.
git branch git branch add-search git switch add-search git switch -c fix-header
Run branch with no arguments and it lists your local branches, marking the current one with an asterisk. Followed by a name, it creates a new branch at your current commit but does not move you to it. The switch command moves you onto a branch, updating your files to match it; the final line combines both steps, creating a branch and switching to it in one move with the c flag. Older tutorials use checkout for the same job, and checkout still works, but switch is the clearer modern command dedicated to branch movement. Daily habit: check your branch with status before committing, because committing a fix to the main branch when you meant to be on a feature branch is an easy mistake in a hurry. The full routine, including naming conventions and cleanup, is laid out step by step in our feature branch workflow notes.
Combining Work: merge
Isolated work eventually has to rejoin the main line. Merging takes the commits from one branch and combines them into the branch you are standing on. It is the command that closes the loop opened by branching, and in a tidy workflow you will use it every time a feature is finished.
git switch main git merge add-search git branch -d add-search
The sequence matters, so read it in order. First you switch to the branch that should receive the work, here main. Then you merge the feature branch into it by name. Git replays or combines the feature commits, and if both branches changed different parts of the code, the merge finishes automatically. If both changed the same lines, Git stops and marks a conflict in the files; you edit those files to the correct combined result, stage them, and commit to finish the merge. The third line deletes the finished feature branch with the d flag once its work is safely merged, keeping the branch list short and honest. Deleting merged branches is housekeeping worth doing weekly, because a list of forty stale branches hides the three that are actually active.
Reading History: log
The log command shows the commit history, newest first: the unique identifier of each commit, its author, its date, and its message. It is your first stop when you ask when did this change, or who touched this file last week.
git log git log --oneline git log --oneline --graph --all
Plain log gives the full detailed view and pages through it, which you exit by pressing q. The oneline flag compresses each commit to a single line with a short identifier and its message, which is the view most developers live in for a quick scan of recent work. Adding graph draws a small text diagram of branches and merges, and all includes every branch rather than only the current one; together they give a compact map of how the project evolved. The short identifiers in this view are also practical: you copy them when you need to point other commands at a specific commit, for example when inspecting or undoing a change.
Pausing Work: stash
Stash is the drawer you sweep work into when you are halfway through a change and something urgent interrupts: a bug on the live site, a colleague needing a review on another branch. Switching branches with unfinished changes can drag those changes along or block the switch entirely. Stash shelves them safely instead.
git stash git switch main # fix the urgent issue, commit it git switch add-search git stash pop
The first line saves your uncommitted changes and returns your files to the last committed state, leaving a clean tree you can safely switch away from. The comment line marks the urgent detour itself. When you return to your original branch, stash pop restores the shelved changes and removes them from the stash list. Treat the stash as short-term parking, not storage. Work left stashed for weeks is easy to forget and painful to reapply after the code has moved on. If the interruption will last, commit the half-finished work on its branch instead, with a message that honestly says work in progress.
Connecting and Housekeeping: remote
The fifteenth command manages the remote connections themselves. You will not run it daily on an established project, but it is essential when setting up, moving a repository to a new host, or diagnosing why pushes go to the wrong place.
git remote -v git remote add origin https://github.com/example/project.git
The v flag lists each remote name alongside the web addresses Git uses to fetch and push, so you can verify at a glance that origin points where you expect. The add line creates that connection in a fresh init project, linking the local repository to its hosted counterpart so the first push has a destination. Together with the other fourteen, this completes the daily toolkit: init or clone to start, status and diff to look, add and commit to save, push, pull, and fetch to sync, branch, switch, and merge to organise work, log to remember, stash to pause, and remote to connect. For connecting to the server itself rather than the repository, our SSH commands cheat sheet covers the login side of remote work.
A Normal Day, Start to Finish
Seeing the loop once, in order, ties the fifteen together. You arrive and run pull on main to start from the latest code. You create and switch to a feature branch. You edit files, checking status and diff as you go. You stage and commit in small pieces with clear messages. When a colleague needs help, you stash, switch, help, return, and pop. When the feature works, you push the branch, merge it into main after review, push main, and delete the branch. Every step in that story is one of the commands above, in the order above. That is not a simplified toy version of professional work; on an ordinary, well-run project, that really is the whole day with Git.
Two small habits multiply the value of these commands. The first is a good ignore file, named .gitignore in the project root, listing files Git should never track, such as dependency folders, build output, and local environment files. It keeps status readable and prevents secrets and bulk from entering history. The second is committing before you experiment. A commit is a save point you can always return to, and the recovery commands in the undo guide are far more effective when recent work is committed rather than floating uncommitted in the tree.
Conclusion
Fifteen commands carry almost all daily Git work: init, clone, status, diff, add, commit, push, pull, fetch, branch, switch, merge, log, stash, and remote. Learn them as a loop rather than a list: look, save, share, organise, remember. Run status and diff more often than feels necessary, commit in small pieces with honest messages, and keep branches short-lived. With that loop fluent, Git stops being a source of anxiety and becomes what it should be, a quiet safety net underneath your actual work.
Tagged: git basics git commands git commit git push pull git tutorial version control



4 thoughts on “Git Basics: The 15 Commands Every Developer Uses Daily”