How to Use Git: The Beginner's Guide (Install, First Commit, Branches, and Your First Push)
CodexFuse Team · 2026-10-29T18:28:00.731Z · 11 min read
How to use Git for the first time: install it, introduce yourself, create a repo, commit, branch, and push to GitHub — the complete beginner workflow with commands you can copy.
How to use Git comes down to five commands you can learn in one sitting: git init starts a project, git add stages your changes, git commit saves them as a checkpoint, git branch lets you experiment safely, and git push sends your work to a service like GitHub. This guide walks you through that exact sequence — install, setup, your first commit, branches, and your first push — in the order a beginner actually needs it. If your code already lives online, read our GitHub beginner guide alongside this one; Git is the tool on your computer, GitHub is where the code lives online.
What is Git, exactly?
Git is a free and open-source distributed version control system — it tracks every change you make to your files, so you can rewind mistakes, try ideas in parallel, and work with other people without stepping on each other's code (git-scm.com, checked October 29, 2026). It was created by Linus Torvalds in 2005 and has since become the standard tool for tracking code changes (Atlassian Git tutorials, fetched October 29, 2026).
Git thinks of your project as three places at once: your working directory (the files you are editing right now), the staging area (the changes you have marked to save next), and the repository (the permanent history of everything you saved). Almost every Git beginner gets confused by this once — a commit saves only what you staged, not everything you changed. Once that clicks, the rest of Git is just commands.
How do I start using Git? (the quick answer)
If you just want the sequence, here it is. The rest of this guide explains each step with the commands you can copy:
- Install Git from git-scm.com and check it with
git --version. - Introduce yourself once:
git config --global user.name "Your Name"andgit config --global user.email "[email protected]". - Create a folder and run
git init -b mainto start a repository. - Make some files, then stage them with
git add .. - Save the checkpoint with
git commit -m "First commit". - Work on new ideas in branches with
git checkout -b feature-name. - Connect to GitHub and push with
git remote add origin <url>andgit push -u origin main.
Step 1: Install Git on your computer
Download the latest version of Git from git-scm.com and run the installer for your operating system (GitHub Docs, "Set up Git," checked October 29, 2026). When it finishes, open a terminal and type git --version — if you see a version number, the install worked.
If you want a nicer terminal to run these commands in, our Warp terminal beginner guide covers a modern option that still runs every Git command exactly the same way.
Step 2: Introduce yourself to Git
Every commit you make gets stamped with a name and email, so Git asks you to set them once before your first commit. These are the exact commands GitHub's own setup guide recommends (GitHub Docs, "Set up Git," checked October 29, 2026):
git config --global user.name "Your Name"git config --global user.email "[email protected]"
The --global flag means this applies to every project on your computer, so you only do it once. Use the same email you will use on GitHub later — that is how GitHub connects your commits to your profile. If you ever want to check what Git remembers about you, run git config --global --list.
Pick an editor for commit messages (optional, takes 30 seconds)
Later, when you commit without the -m flag, Git opens a text editor for your message. You can set your favorite editor in advance, for example Visual Studio Code with git config --global core.editor "code --wait". New to that editor? Our VS Code beginner guide walks through the first setup.
Step 3: Create your first repository
A repository (repo) is just a folder that Git watches. Make a folder, step inside it, and initialize it:
mkdir my-first-projectcd my-first-projectgit init -b main
Git answers with Initialized empty Git repository in .git/ — that hidden .git folder is where all your history will live (git-scm.com docs, "gittutorial," fetched October 29, 2026).
Notice the -b main part. Older Git versions default to a branch called master, but GitHub creates new repos on main — and mismatched names are the single most common first-push error ("src refspec main does not match any"). Naming your branch main at the start avoids that trap entirely.
Step 4: Make your first commit
Commits are checkpoints. To make one, you do two things: first you stage changes (tell Git what to include), then you commit (save the checkpoint). Create a file to practice with:
echo "Hello, Git!" > hello.txtgit status
git status is your best friend — it tells you what changed, what is staged, and what branch you are on. You will run it constantly. Now stage and commit:
git add hello.txtgit commit -m "Add hello.txt"
That -m message is a short description of what changed. If your folder already has files, git add . stages everything at once (CodeClouds, "Beginners Tutorial: Getting Started with Git," updated October 29, 2026). Check your work with git log, which shows the history of every commit you have made.
The 15 Git commands that cover 95% of daily work
You do not need to memorize all of Git. These are the commands working developers reach for every day — learn this table and you can use Git:
| Command | What it does | When you use it |
|---|---|---|
git init -b main | Turns a folder into a repository | Starting a brand-new project |
git clone <url> | Copies a whole repo from the internet | Joining an existing project |
git status | Shows what changed and what is staged | Before every commit, honestly |
git add <file> | Stages a change for the next commit | After editing, before committing |
git commit -m "msg" | Saves staged changes as a checkpoint | Every time a small unit of work is done |
git log | Lists past commits | Reviewing history or finding a mistake |
git diff | Shows unstaged changes line by line | Double-checking before you commit |
git branch | Lists branches (or creates one with a name) | Seeing or starting lines of work |
git checkout -b <name> | Creates a branch and switches to it | Starting a new feature |
git switch <name> | Moves between branches | Jumping between tasks |
git merge <branch> | Folds a branch's changes into the current one | Finishing a feature |
git pull | Fetches and applies others' changes | Before you start work, and often |
git push | Sends your commits to the remote | Backing up and sharing your work |
git stash | Shelves uncommitted changes temporarily | Switching branches mid-task |
.gitignore | File listing what Git should never track | Keeping secrets and junk out of commits |
How branches keep your experiments safe
A branch is a parallel copy of your project where you can work without touching the main line. The standard habit is one branch per task: start it, do the work, merge it back, delete it. Here is the full loop:
git checkout -b add-login-page# edit files, then...git add .git commit -m "Add login page"git switch maingit merge add-login-page
If you and someone else edited the exact same lines, Git pauses the merge and asks you to resolve the merge conflict by hand — it marks the clashing sections in the file, you pick the right version, then git add the file and git commit to finish (CodeClouds, updated October 29, 2026; GeeksforGeeks, "Using Git and GitHub," updated January 19, 2026). Conflicts look scary the first time but are completely normal; when in doubt, ask a teammate before committing the resolution.
How to push your first repo to GitHub
Your commits live on your computer until you push them somewhere. GitHub is the most common somewhere — create a new repository there (public or private), then connect your local repo to it:
git remote add origin https://github.com/yourname/my-first-project.gitgit push -u origin main
The -u sets the upstream, so future pushes need only git push. When GitHub asks for credentials, it will not accept your account password — authenticate with HTTPS using a personal access token, with an SSH key, or let GitHub CLI handle it (gh auth login); you can cache HTTPS credentials with a credential helper so you are not asked every time (GitHub Docs, "Set up Git," checked October 29, 2026).
From here the daily loop is simple: git pull to get others' changes, do your work on a branch, commit, and git push. Teammates review your work through pull requests — proposed changes they can comment on and merge.
How to undo a mistake in Git
Everyone commits something wrong eventually. Match the fix to the situation:
- Haven't committed yet:
git restore <file>throws away the working-copy changes and goes back to the last commit. - Committed, but haven't pushed:
git reset --soft HEAD~1undoes the last commit while keeping your changes staged, so you can redo it properly. - Already pushed, or want a public record:
git revert <commit>creates a new commit that undoes the old one — safe to share with a team.
The one hard rule: never rewrite history that other people already have (no force-pushing shared branches). Reverting adds a commit; rewriting pretends the old one never existed, and that breaks everyone else's copy.
Git vs GitHub: what's actually different?
Beginners mix these up constantly. One sentence settles it: Git is the tool, GitHub is a website that hosts what Git makes.
| Git | GitHub | |
|---|---|---|
| What it is | Version control software on your computer | A web platform built on top of Git |
| Works offline? | Yes — commits, branches, history all local | No — it's a website |
| Costs money? | Free and open source, forever | Free accounts; paid tiers for teams |
| What it adds | Nothing — it's the engine | Pull requests, issues, code review, CI/CD |
| Alternatives | Mercurial, Subversion | GitLab, Bitbucket, Gitea |
Good habits that keep your history clean
These five habits come straight from the best-practices sections of the beginner guides (GeeksforGeeks, updated January 19, 2026):
- Commit small and often with clear messages — "Fix login button on mobile" beats "stuff."
- Use descriptive branch names like
feature/signup-formorbugfix/header-overlapso anyone can tell what a branch is for. - Pull before you push — syncing first avoids most merge conflicts.
- Add a
.gitignoreearly — exclude things likenode_modules/,*.log, and API keys before they ever get committed. - Stash, don't commit, half-done work —
git stashshelves your changes so you can switch branches cleanly, andgit stash popbrings them back.
And if you write code with AI assistance, our GitHub Copilot beginner guide covers how the coding assistant plugs into this same workflow.
Sources
- CodeClouds, "Beginners Tutorial: Getting Started with Git" (codeclouds.com/blog/what-is-git-and-how-do-you-use-it/) — updated October 29, 2026; install flow, staging model, branching, merge-conflict basics.
- GeeksforGeeks, "Using Git and GitHub" (geeksforgeeks.org/git/how-to-use-git-and-github/) — updated January 19, 2026; full command sequence, GitHub push/pull flow, pull requests, rebase/squash/.gitignore/stash tips, best practices.
- GitHub Docs, "Set up Git" (docs.github.com/en/get-started/git-basics/set-up-git) — checked October 29, 2026; install, username/email config, HTTPS vs SSH authentication, credential helpers, GitHub CLI.
- git-scm.com — checked October 29, 2026; "free and open source distributed version control system"; gittutorial import/add/commit walkthrough.
- Atlassian, "How to Use Git? Tutorials, Workflows & Commands" (atlassian.com/git) — fetched via search October 29, 2026; Git created by Linus Torvalds in 2005, distributed model, branching workflows.
Frequently asked questions
Do I need GitHub to use Git?
No. Git runs entirely on your own computer — you can init, commit, and branch with no account anywhere. GitHub (or GitLab, Bitbucket, Gitea) is where you push that history when you want a backup, a portfolio, or teammates.
What is the difference between git add and git commit?
git add stages changes — it marks what will go into the next checkpoint. git commit saves the checkpoint itself. Skipping git add and wondering why your commit is "empty" is the classic beginner moment.
Why does Git ask me to sign in every time I push?
You probably haven't set up credential caching. With HTTPS, configure Git's credential helper so it remembers your personal access token; with SSH, add your key to the ssh-agent. GitHub's own setup guide lists both routes (GitHub Docs, checked October 29, 2026).
Is Git free?
Yes — Git is free and open-source software (git-scm.com). You never pay for Git itself; hosting services like GitHub offer free accounts with paid tiers for teams.
Git says "src refspec main does not match any" — what went wrong?
Your local branch and the remote branch have different names — usually your repo is on master while GitHub expects main. Fix it once with git branch -M main, or avoid it entirely by running git init -b main when you start a project.