Git is a version control system that records changes to your files. The basic workflow is: git init to create a repository, git add to stage changes, git commit -m "message" to save a snapshot, git switch -c branch-name to work on a feature, git merge to combine work, and git push to send commits to a remote such as GitHub.
Learning how to use Git can feel intimidating at first — a wall of commands and messages about “HEAD” and “detached states”. But underneath, the idea is friendly: Git takes snapshots of your project so you can always go back, try ideas safely and work with other people without overwriting each other’s changes.
You only need a handful of commands for everyday work. Learn those well, and the rest can wait until you actually need it.
Install and configure Git
Download Git from git-scm.com (Windows), use Xcode Command Line Tools or Homebrew (macOS), or your package manager (Linux). Then set your identity:

git config --global user.name "Your Name"
git config --global user.email "you@example.com"
git config --global init.defaultBranch main
How to use Git: create a repository and commit
mkdir my-site && cd my-site
git init
echo "# My Site" > README.md
git status
git add README.md
git commit -m "Add README"
git log --oneline

Essential Git commands
| Command | What it does |
|---|---|
git status |
Shows changed and staged files |
git add . |
Stages all changes |
git commit -m "msg" |
Saves a snapshot |
git diff |
Shows unstaged changes |
git log --oneline |
Shows commit history |
git switch -c feature |
Creates and switches to a branch |
git merge feature |
Merges a branch into the current one |
git pull |
Fetches and merges remote changes |
git push |
Uploads commits to the remote |
Branching and merging
git switch -c new-header
# edit files...
git add .
git commit -m "Redesign header"
git switch main
git merge new-header
Undoing changes safely
| Situation | Command |
|---|---|
| Discard changes to a file | git restore file.html |
| Unstage a file | git restore --staged file.html |
| Fix the last commit message | git commit --amend (before pushing) |
| Undo a pushed commit | git revert <commit> |
Ignore files with .gitignore
node_modules/
.env
dist/
*.log
Warning: Never commit passwords, API keys or .env files. If you do, change the secrets immediately — removing them from a later commit does not remove them from history.

Connect to a remote
git remote add origin https://github.com/your-username/my-site.git
git push -u origin main
A typical day with Git
- Get the latest changes
git pullon your main branch. - Start a feature branch
git switch -c add-contact-form - Work and commit oftenSmall commits with messages like “Add contact form validation”.
- Push your branch
git push -u origin add-contact-form - Open a pull requestAsk for review and let checks run.
- Merge and tidy upMerge, switch back to main, pull and delete the old branch.
Writing good commit messages
| Weak | Better |
|---|---|
| “fix” | “Fix mobile menu not closing on link click” |
| “changes” | “Add pricing table to services page” |
| “update stuff” | “Update footer links and copyright year” |
Merge conflicts without panic
- Read which files have conflicts (
git status). - Open each file and find the conflict markers.
- Decide which lines to keep — sometimes a mix of both.
- Remove the markers, save and test.
- Stage the files and commit the merge.
Tip: Use a visual Git tool such as the Source Control panel in VS Code or GitHub Desktop alongside the command line. Seeing changes visually makes Git much easier to learn.
Continue with GitHub for beginners and Git and GitHub guides.
Frequently asked questions
What is the difference between Git and GitHub?
Git is version control software on your computer. GitHub is an online service that hosts Git repositories and adds collaboration tools.
How often should I commit?
Commit each small, complete change with a clear message, often several times a day.
What does git pull do?
It fetches changes from the remote repository and merges them into your current branch.
How do I undo my last commit?
If not pushed, use git reset –soft HEAD~1 to keep changes. If pushed, use git revert to create an undo commit.
Is Git hard to learn?
The basics — add, commit, push, pull and branch — can be learned in an afternoon. Advanced features take longer but are only needed occasionally.
Can I use Git for WordPress sites?
Yes. Many developers track themes and custom plugins in Git, and some deploy changes to servers from Git repositories.
What should I never commit to Git?
Passwords, API keys, .env files, large media uploads and dependency folders such as node_modules.
Further reading: MDN’s web development learning area.







