Git for Beginners: The Essential Commands You Actually Need
Learn the Git commands that matter most for beginners. This practical guide covers init, add, commit, push, pull, branch, and merge with clear examples and common workflows.
Learn2Code Team
January 24, 2026
Why Every Developer Needs Git
Git is the version control system used by virtually every software team in the world. GitHub alone hosts over 200 million repositories. Whether you are building a personal project or working at a Fortune 500 company, you will use Git daily.
Version control solves a fundamental problem: how do you track changes to your code over time, collaborate with others, and undo mistakes without losing work? Before Git, developers emailed zip files to each other and named folders "project-v2-final-FINAL." Git replaced that chaos with a system that tracks every change, who made it, and why.
If you are learning to code and have not learned Git yet, now is the time. It is a core skill that every job posting expects.
The Mental Model: Snapshots, Not Diffs
The easiest way to understand Git is to think of it as a camera for your code. Every time you "commit," Git takes a snapshot of all your files at that moment. You can look back at any snapshot, compare snapshots, or restore your project to any previous snapshot.
Your project has three main areas in Git:
- Working directory -- the files you see and edit on your computer
- Staging area -- files you have marked to include in your next snapshot
- Repository -- the collection of all snapshots (commits) you have made
The typical workflow is: edit files, stage the changes, then commit the snapshot. Each commit has a message describing what changed and why.
Setting Up Git
Before using Git, configure your identity. This information appears on every commit you make.
1git config --global user.name "Your Name"2git config --global user.email "your.email@example.com"Check your configuration:
1git config --listThe 10 Commands You Need
1. git init -- Start a New Repository
1# Create a new project folder and initialize Git2mkdir my-project3cd my-project4git initThis creates a hidden .git folder that stores all version history. You only run this once per project.
2. git clone -- Copy an Existing Repository
1# Clone a repository from GitHub2git clone https://github.com/username/repository-name.gitThis downloads the entire project and its history to your computer. Use this when joining an existing project.
3. git status -- Check What Has Changed
1git statusThis is the command you will run most often. It shows which files have been modified, which are staged for commit, and which are untracked (new files Git does not know about yet).
4. git add -- Stage Changes
1# Stage a specific file2git add index.html3 4# Stage multiple files5git add index.html style.css6 7# Stage all changes in the current directory8git add .Staging does not save anything permanently. It prepares files for the next commit. Think of it as loading film into the camera before taking the photo.
5. git commit -- Save a Snapshot
1# Commit staged changes with a message2git commit -m "Add navigation bar to homepage"Each commit is a permanent snapshot. The message should describe what you changed and why. Good commit messages make it easy to understand your project's history months later.
Good commit messages:
- "Fix login button not responding on mobile"
- "Add user profile page with avatar upload"
- "Remove deprecated API endpoint for v1 users"
Bad commit messages:
- "fix stuff"
- "update"
- "asdf"
6. git log -- View History
1# See commit history2git log3 4# Compact one-line format5git log --oneline6 7# Show last 5 commits8git log --oneline -5Each commit shows its unique ID (a hash like a1b2c3d), the author, the date, and the message.
7. git branch -- Work on Features Separately
1# List all branches2git branch3 4# Create a new branch5git branch feature-login6 7# Switch to a branch8git checkout feature-login9 10# Create and switch in one command11git checkout -b feature-loginBranches let you work on new features without affecting the main code. When the feature is ready, you merge it back. This is how teams work on multiple features simultaneously without breaking each other's code.
8. git merge -- Combine Branches
1# Switch to main branch2git checkout main3 4# Merge feature branch into main5git merge feature-loginThis takes all the commits from feature-login and applies them to main. If both branches changed the same lines, Git will flag a "merge conflict" that you resolve manually.
9. git push -- Upload to Remote
1# Push commits to the remote repository2git push origin main3 4# Push a new branch to remote5git push -u origin feature-loginThis sends your local commits to a remote server (usually GitHub, GitLab, or Bitbucket) where others can see and pull your changes.
10. git pull -- Download Updates
1# Pull latest changes from remote2git pull origin mainThis downloads and merges any new commits from the remote repository into your local branch. Run this before starting new work to make sure you have the latest code.
The Daily Workflow
Here is the workflow you will use 90% of the time:
1# 1. Pull latest changes2git pull origin main3 4# 2. Create a branch for your work5git checkout -b feature-new-button6 7# 3. Make your changes (edit files)8 9# 4. Check what changed10git status11 12# 5. Stage your changes13git add .14 15# 6. Commit with a descriptive message16git commit -m "Add submit button to contact form"17 18# 7. Push to remote19git push -u origin feature-new-button20 21# 8. Create a pull request on GitHub (done in the browser)22 23# 9. After the PR is merged, switch back to main24git checkout main25git pull origin mainCommon Mistakes and How to Fix Them
"I committed to the wrong branch"
1# Undo the last commit but keep the changes2git reset HEAD~13 4# Now switch to the correct branch5git checkout correct-branch6 7# Stage and commit again8git add .9git commit -m "Your message""I want to undo my last commit"
1# Undo commit, keep changes staged2git reset --soft HEAD~13 4# Undo commit, keep changes unstaged5git reset HEAD~16 7# Undo commit and discard changes (dangerous!)8git reset --hard HEAD~1"I have merge conflicts"
Merge conflicts happen when two branches change the same lines. Git marks the conflicts in your files:
1<<<<<<< HEAD2Your version of the code3=======4Their version of the code5>>>>>>> feature-branchTo resolve: edit the file to keep the code you want, remove the conflict markers (<<<<<<<, =======, >>>>>>>), then stage and commit.
"I want to see what changed before committing"
1# See unstaged changes2git diff3 4# See staged changes5git diff --staged.gitignore -- Files Git Should Ignore
Create a .gitignore file in your project root to tell Git which files to ignore:
1# Dependencies2node_modules/3 4# Environment variables5.env6 7# Build output8dist/9build/10 11# OS files12.DS_Store13Thumbs.dbNever commit node_modules, .env files, or build output. These are either too large, contain secrets, or can be regenerated.
Git vs GitHub
Git and GitHub are not the same thing:
- Git is the version control tool that runs on your computer
- GitHub is a website that hosts Git repositories and adds collaboration features (pull requests, issues, code review)
You can use Git without GitHub (with GitLab, Bitbucket, or even just locally). But GitHub is where most open-source projects live and where employers look for your portfolio.
Next Steps After the Basics
Once you are comfortable with the commands above, explore these topics:
- Pull requests -- the standard way to propose changes on teams
- Rebasing -- an alternative to merging that creates a cleaner history
- Stashing -- temporarily save changes without committing
- Cherry-picking -- apply a specific commit from one branch to another
- Git hooks -- automate tasks before or after commits
Start Using Git Today
If you are writing code without Git, you are one bad edit away from losing everything. Git is not just a collaboration tool -- it is a safety net for your work.
Start by initializing Git in your current project (git init), making your first commit, and pushing to a GitHub repository. From there, the daily workflow becomes second nature within a week.
Related Reading
- How to Learn JavaScript from Scratch -- Git is a core tool in every JavaScript developer's workflow
- Coding Interview Preparation Guide -- employers expect Git proficiency in technical interviews
- How to Practice Coding Effectively -- track your coding progress with Git commits
