Skip to content
VarSys Learn
DEVProgramming

Git for Beginners: The Commands You Will Actually Use

Git has hundreds of commands, but daily work needs about a dozen. Learn those, with plain explanations and safe ways to undo mistakes.

A terminal window on a laptop showing a colourful Git log graph with several branches merging

Key points

  • Git saves snapshots of your project called commits, so you can always go back.
  • The daily loop is: edit, git status, git add, git commit, git push.
  • Branches let you try changes without breaking the main version.
  • Check git status before and after every command while you are learning.
On this page
  1. Why use Git at all?
  2. How to set up Git and start a repository
  3. Configure Git once
  4. Create or copy a repository
  5. The everyday Git workflow
  6. Working with branches and remotes
  7. Branches
  8. Syncing with a remote repository
  9. How to undo mistakes in Git
  10. Your next step
  11. Frequently asked questions

Git is a version control system that records snapshots of your project over time. As a beginner you only need a small set of commands: init or clone to start, status, add and commit to save work, branch and switch to try ideas safely, and pull and push to sync with a remote such as a hosted repository.

This guide explains each one in plain language, in the order you will use them.

Why use Git at all?

Without version control, people end up with folders full of files named like final, final-2 and final-really. Git replaces that with one clean folder and a complete, searchable history. You can see what changed, when and why, return to any earlier version, and work with other people on the same files without overwriting each other.

Git is not only for large teams. Solo learners benefit just as much, because it makes experimenting safe: if an idea breaks everything, you go back to the last working commit.

How to set up Git and start a repository

Configure Git once

After installing Git, tell it who you are. This name and email are attached to every commit you make.

git config --global user.name "Your Name"
git config --global user.email "you@example.com"
git config --global init.defaultBranch main

Create or copy a repository

  • git init turns the current folder into a new repository.
  • git clone <url> downloads an existing repository, including its full history.
  • A .gitignore file lists things Git should never track, such as virtual environments, build output and files containing secrets.

The everyday Git workflow

Most of your time with Git follows the same loop. Files move from your working folder, to the staging area (what will go in the next snapshot), to a commit.

  1. Edit your files as normal.
  2. Run git status to see what changed.
  3. Run git diff to review the exact lines you changed.
  4. Stage the files you want with git add <file>.
  5. Save the snapshot with git commit -m "Describe the change".
  6. Share it with git push.
git status
git diff
git add app.py README.md
git commit -m "Add input validation to the signup form"
git push

Working with branches and remotes

Branches

A branch is a separate line of work. You can experiment on a branch and merge it back only when it works.

Common branch commands
CommandWhat it does
git branchLists branches and shows which one you are on
git switch -c new-featureCreates a new branch and switches to it
git switch mainMoves back to the main branch
git merge new-featureBrings the branch's commits into the current branch
git branch -d new-featureDeletes a branch that has already been merged

Syncing with a remote repository

  • git pull fetches new commits from the remote and merges them into your branch.
  • git push uploads your commits.
  • git log --oneline --graph shows a compact history so you can see where branches split and joined.

If two people changed the same lines, Git stops and marks a merge conflict in the file. Open it, keep the correct version between the markers, remove the markers, then git add and git commit to finish.

How to undo mistakes in Git

  • git restore <file> discards uncommitted changes to a file.
  • git restore --staged <file> removes a file from the staging area but keeps your edits.
  • git commit --amend fixes the message or contents of your last commit, before you push it.
  • git revert <commit> creates a new commit that undoes an earlier one, which is safe for shared history.

Your next step

Create a practice folder, run git init, and make five small commits while watching git status after each one. Then use it for your first projects from our Python roadmap. Keep any account tokens in a password manager, never inside your repository.

Frequently asked questions

What is the difference between Git and a hosted Git service?

Git is the version control tool that runs on your computer. Hosting services store a copy of your repository online so you can back it up and collaborate.

What does git add actually do?

It moves changes into the staging area, which is a list of what will be included in your next commit. Nothing is saved to history until you commit.

What is the difference between git pull and git fetch?

git fetch downloads new commits without changing your files. git pull fetches and then merges them into your current branch.

How often should I commit?

Commit whenever you finish a small, working step. Small, frequent commits are easier to understand and to undo.

Share this guide

Written by

Founder and CEO of VarSys

Vasanthan writes practical career guides about job searching, workplace skills and technology used at work.

Get the best of Programming, weekly

New guides and the updates worth knowing about. No spam, unsubscribe in one click.