Skip to main content

Git Beginner Quick Start Guide

Who This Is For​

If you're just starting with Git and haven't fully sorted out the relationship between the working directory, staging area, commit history, and remote repository, this is the best place to start.

The goal isn't to learn every command at once, but to build a minimal workflow that lets you "work reliably without easily messing up the repository."

Git's Minimal Model First​

Think of Git as this pipeline:

Working Directory -> git add -> Staging Area -> git commit -> Local Repository -> git push -> Remote Repository

Four core concepts:

  • Working Directory: The files you're currently editing.
  • Staging Area: What's ready to be included in the next commit.
  • Local Repository: Versions already committed to local history.
  • Remote Repository: The repository copy on GitHub, GitLab, Gitee, etc.

As long as you remember this, many commands won't get confusing.

First-Time Configuration​

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

Check your configuration:

git config --list

If you haven't set up your environment yet, see Installing and Configuring Git.

Two Ways to Get Started​

Option 1: Create a New Repository​

mkdir my-project
cd my-project
git init
git status

First commit:

git add .
git commit -m "init: first commit"

Option 2: Clone an Existing Repository​

git clone <repository-url>
cd <repository-folder>
git status

8 Core Commands to Learn First​

CommandPurposeHow Beginners Should Think About It
git statusCheck current stateRun it first whenever you're unsure
git addMove changes to stagingTell Git "these changes are ready to commit"
git commit -mCreate a local commitWrite staged content into history
git log --onelineView commit historyQuick review of recent commits
git diffSee unstaged changesCheck content before committing
git switchSwitch branchesClearer than checkout
git pullPull remote updatesSync first, then continue developing
git pushPush to remoteSync local commits outward

The Most Common Daily Workflow​

1. Check Status Before Starting​

git status
git branch --show-current

2. Create a Separate Branch for New Tasks​

git switch -c feature/login

3. Check After Modifying Files​

git status
git diff

4. Stage and Commit After Confirming​

git add <file>
git commit -m "feat: add login page"

To stage all changes in the current directory at once:

git add .

5. Push a New Branch for the First Time​

git push -u origin $(git branch --show-current)

After that, pushing the same branch usually only requires:

git push

Learn to Read git status First​

The most common statuses:

  • ?? file.txt: Untracked file -- Git hasn't taken it over yet.
  • M file.txt: Modified in working directory, but not yet git add-ed.
  • M file.txt: Modification has been staged.
  • A file.txt: New file has been staged.
  • D file.txt: Deletion has been staged.

If you're always confused about your current state, start by reading View Files in the Current Git Repository.

6 Most Common Beginner Problems​

1. git add-ed the Wrong File​

git restore --staged <file>

See Git Undo git add Operation Guide for details.

2. Working Directory Changes Are a Mess, Want to Discard​

git restore <file>

See Git Discard Working Directory Changes Guide for details.

3. Lots of Temporary Files, Build Artifacts​

git clean -nd
git clean -fd

See Git Clean Untracked Files Guide for details.

4. Need to Switch Tasks Midway​

git stash push -u -m "wip"

See Git stash Guide for details.

5. Just Committed and Regret It, But Haven't Pushed​

git reset --soft HEAD~1

See Git Commit Undo Guide for details.

6. Already Pushed a Bad Commit​

git revert <commit>

See Git revert Guide for details.

Commands Beginners Should Avoid for Now​

These commands aren't impossible to learn, but aren't recommended before you understand the consequences:

  • git reset --hard
  • git push -f
  • git rebase
  • git cherry-pick
  • git filter-repo

The reason is simple: they're more likely to rewrite history, overwrite local changes, or make collaboration branches hard to understand.

A Practical Learning Sequence​

Phase 1: Learn "Daily Commits"​

Focus only on:

git status
git add
git commit
git log --oneline
git push

Phase 2: Learn "Undo" and "Restore"​

Focus on:

Phase 3: Learn "Branch Collaboration"​

Focus on:

Phase 4: Learn Advanced Topics​

Focus on:

Three Final Tips for Beginners​

  • When unsure, run git status first -- don't guess.
  • Understand "working directory / staging area / commit history" before learning various undo commands.
  • On shared branches, prefer safe, traceable approaches -- don't treat force push as a daily operation.