Quick Start with Simple Git Commands

Git Core Commands Quick Start Guide for Beginners

I. Core Command Cheat Sheet

Command Core Function Layman’s Explanation
git fetch Downloads the latest code from the remote repository (synchronization only, no local changes) “Take a quick look” at the latest content in the remote repository and copy it locally (without touching your local files)
git pull Downloads the latest remote code and automatically merges it into the current branch One-stop operation combining fetch + merge, directly synchronizing the latest remote content to your local repository
git merge Merges code from a remote or other branch into the current branch Integrates the remote code you “looked at” (and copied locally) into the files you’re currently developing
git add Adds local modifications to the staging area (preparing for commit) Tells Git: “I intend to commit these changes—please stage them first.”
git commit Commits staged changes to the local repository Assigns a “version label” to your local changes, recording what was modified
git push Pushes local commits to the remote repository Uploads your locally labeled changes to the remote repository (e.g., GitHub/GitLab)

II. Must-Learn Workflow for Beginners: Complete Development Process (Step-by-Step Practical Guide)

Step 1: Synchronize Latest Remote Code (Two Options Available)

Before starting development, always synchronize the latest remote code to avoid conflicts with others’ changes. Choose the method best suited to your scenario:

Method 1: fetch + merge (Recommended — highly controllable; ideal for beginners)

Execute step-by-step: first inspect remote changes, then merge — preventing blind merges that may trigger conflicts.

# Run
# 1. Download the latest updates from all branches of the remote repository (origin)  
#    (downloads only — does not modify local files)
git fetch origin

# 2. Merge the latest code from the remote dev branch into your current local branch  
#    (resolves synchronization issues)
git merge origin/dev

Method 2: git pull (Convenient, one-step sync)

Performs fetch + merge in a single command — suitable when there are no uncommitted local changes and you’re confident no conflicts exist (e.g., solo development):

# Run
# Pull and merge the remote dev branch (from origin) directly into your current local branch
git pull origin dev

# If your current branch is already associated with a remote branch, simplify to:
git pull

:white_check_mark: General Key Reminders:

  • If merging or pulling triggers a “file locked/conflict” message, first close programs occupying those files (e.g., editors, running processes).
  • For conflicts involving logs or temporary files, simply delete the local conflicting files (they aren’t version-controlled), then re-run the sync command.

Step 2: Commit Local Modifications (add + commit)

After completing development, commit your local changes to the local repository:

# Run
# 1. Stage all local modifications (new/modified/deleted files)
git add -A

# 2. Commit staged changes with a clear, descriptive message (explaining what changed)
git commit -m "Modification: removed vital signs field | Addition: log ignore rules"

:white_check_mark: Key Reminders:

  • git add -A is recommended for beginners (covers all modifications); alternatively, specify individual files: git add src/backend/app.py.
  • Commit messages must be clear and meaningful (e.g., “Fix: login API error”), facilitating future version history review.

Step 3: Push to Remote Repository (push)

After committing locally, push your changes to the remote repository so your team can access them:

# Run
# Push commits from your current local branch to the dev branch on remote origin
git push origin dev

# For the first push of this branch, set the upstream tracking branch (subsequent pushes can use `git push` alone)
git push -u origin dev

:white_check_mark: Key Reminders:

  • Ensure you’ve synchronized the latest remote code (Step 1) before pushing, to avoid push conflicts.
  • If you encounter an “insufficient permission” error, verify that your remote repository account has push permissions.