Git Basics
Every professional developer uses Git. You do not need to master it β but you need to understand what it does and why your team uses it. This page covers the minimum.
Quick start: Install Git or GitHub CLI
Section titled βQuick start: Install Git or GitHub CLIβOption A: GitHub CLI (Recommended)
Section titled βOption A: GitHub CLI (Recommended)βWindows:
winget install GitHub.cliOr download from: cli.github.com
macOS:
brew install ghLinux:
sudo apt install gh # Debian/UbuntuAuthenticate:
gh auth loginFollow the prompts β choose GitHub.com β HTTPS β Login with browser.
Verify:
gh --versionOption B: Git (Full version control)
Section titled βOption B: Git (Full version control)βWindows: Download from git-scm.com
macOS:
xcode-select --installLinux:
sudo apt install gitConfigure:
git config --global user.name "Your Name"git config --global user.email "your.email@xjtlu.edu.cn"Authenticate:
gh auth login # GitHub CLI handles Git auth tooVerify:
git --versionNext: Connect to AI coding tools
Section titled βNext: Connect to AI coding toolsβOnce Git is installed, you can use it with AI coding tools:
- OpenCode Desktop β Standalone AI coding app with GitHub Copilot integration, multiple AI models (Claude, GPT-4o), and autonomous agent mode
- GitHub Copilot β VS Code extension with inline completions and chat
- Cursor β VS Code-like editor with built-in AI agent
See the full comparison: AI Coding Tools
Watch: Git and GitHub in 100 seconds
Section titled βWatch: Git and GitHub in 100 secondsβStart here β 100 seconds, everything you need to know at a glance.
What is version control?
Section titled βWhat is version control?βVersion control is a system that records every change you make to your code. You can see who changed what, when, and why. You can go back to any earlier version at any time.
Without version control: one person rewrites a file, the old version is gone. Two people edit the same file at the same time, one overwrites the other. You cannot trace why something broke.
With Git: every change is saved. Every person has a full copy of the history. Conflicts are caught and merged deliberately.
Why Git specifically?
Section titled βWhy Git specifically?βGit is the industry standard. GitHub (where you store and share your code) is built on Git. Every professional team you join will use Git. AI coding tools (GitHub Copilot, Cursor, Claude Code) all integrate with Git. Learning the basics now means you speak the same language as every developer you will ever work with.
The four things you must know
Section titled βThe four things you must knowβA branch is an isolated copy of your codebase where you can work safely without affecting everyone else.
Why it matters: your main branch should always contain working code. You create a new branch for each feature or fix, work on it, then merge it back when it is done and tested.
main ββββββββββββββββββββββββββββββββββββββββββββββΊ (always working) βββ feature/feeding-log βββΊ (your work) βββΊ merge backCommon commands:
git checkout -b feature/feeding-log # create and switch to a new branchgit checkout main # switch back to mainA commit is a saved snapshot of your changes with a message describing what you did.
Why it matters: commits are the history. Your pathfinder can see exactly what you did and when. βI worked on the app this weekβ is invisible β a commit with a clear message is permanent evidence of your contribution.
Good commit messages:
feat: add cat profile form with name and photo uploadfix: prevent duplicate feeding entries within 10 minutesdocs: add acceptance criteria to feeding log user storyBad commit messages:
updatechangesasdfghThe command:
git add . # stage all changed filesgit commit -m "feat: add feeding log form" # save the snapshotPush sends your commits from your local machine to GitHub so the rest of the team can see your work.
Why it matters: code on your laptop only is not code your team or pathfinder can see. Push at the end of every working session.
git push # send commits to GitHubgit push origin feature/feeding-log # push a specific branchPull downloads the latest changes from GitHub to your local machine.
Why it matters: before you start working, always pull. Otherwise you are working on an old version and will get conflicts when you try to push.
git pull # get latest changes from GitHubThe daily loop
Section titled βThe daily loopβpull β work β commit β pushgit pullβ get everyone elseβs latest changes- Write your code
git add .thengit commit -m "what you did"β save your workgit pushβ share it with the team
Repeat. That is all of it.
Watch: Git in depth (~13 min)
Section titled βWatch: Git in depth (~13 min)βIf you want to understand the concepts properly before using the commands, this longer walkthrough is worth it.
Canβt access YouTube? Search for βGit and GitHub introductionβ or βGit explained beginnersβ on Bilibili or any platform you can reach β there are good short videos in both English and Chinese.
Minimum viable Git setup
Section titled βMinimum viable Git setupβIf your team is not yet using Git properly, fix this now. The minimum:
- One shared GitHub repository (created by the Technical Lead)
- Everyone cloned β
git clone <repo-url> - Each developer works on their own branch
- Merge to
mainonly when the feature works
This is enough for your sprint. You do not need Pull Requests, Actions, or automated tests yet β those come later.
If something goes wrong
Section titled βIf something goes wrongβGit errors are normal. Common ones and what to do:
| Error | What it means | Fix |
|---|---|---|
merge conflict | Two people edited the same lines | Open the file, find the conflict markers <<<<, decide which version to keep, then commit |
rejected β non-fast-forward | Someone else pushed before you | Run git pull first, then try git push again |
nothing to commit | No changes since your last commit | You are already up to date |
detached HEAD | You checked out a commit directly | Run git checkout main to get back |
When in doubt: do not force-push to main. Ask a teammate or search the exact error message.
Was this page helpful?