In this guide: Git for beginners explained in plain English: what version control is, installing Git, your first commit, branches and merging, and pushing to GitHub.
Have you ever edited your website’s code, broken something, and wished you could just go back to yesterday’s version? That’s exactly what Git does. It’s a version control system that tracks every change to your files, so you can undo mistakes, experiment safely, and collaborate without overwriting each other’s work.
What version control is
Version control is a system that records changes to files over time. Think of it as an unlimited, organized “undo history” with notes.
With Git, you can:
- Save snapshots of your project (called commits).
- See exactly what changed, when, and why.
- Go back to any previous version.
- Work on new features in separate branches without affecting the main code.
- Collaborate with other developers and merge their work.
- Back up your code to online services like GitHub, GitLab, or Bitbucket.
A few key terms:
- Repository (repo): a project folder tracked by Git.
- Commit: a saved snapshot with a message describing the change.
- Branch: a separate line of development.
- Merge: combining changes from one branch into another.
- Remote: a copy of the repository hosted online (like GitHub).
- Push / Pull: send commits to / get commits from the remote.
Installing Git
- Windows: download Git for Windows from git-scm.com. It includes Git Bash, a terminal.
- macOS: run
git --versionin Terminal; if Git isn’t installed, macOS prompts you to install developer tools. Or install via Homebrew. - Linux: use your package manager, e.g.,
sudo apt install git.
Then set your name and email (used in commit history):
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
Prefer visual tools? GitHub Desktop and the Git features built into code editors like VS Code make Git easier to learn.
Your first commit
-
Create or open a project folder in your terminal:
bash
cd my-website
git init
This creates a hidden.gitfolder that stores history. -
Check the status:
bash
git status
Git lists untracked files. -
Stage files (choose what goes into the next snapshot):
bash
git add index.html style.css
# or stage everything:
git add . -
Commit with a clear message:
bash
git commit -m "Add homepage layout and base styles" -
View history:
bash
git log --oneline
Good commit messages describe what and why: “Fix mobile menu overlapping header” is better than “update.”
Create a .gitignore file to exclude files you shouldn’t track — like node_modules/, .env files with passwords, or WordPress wp-config.php with database credentials. Never commit passwords or API keys.
Branches and merging
Branches let you work on something new without risking your working code.
git branch # list branches
git switch -c new-contact-form # create and switch to a new branch
# ...make changes, add, commit...
git switch main # go back to main
git merge new-contact-form # bring the changes into main
If two branches change the same lines, Git reports a merge conflict. Open the file, choose which changes to keep, remove the conflict markers, then add and commit.
Common workflow:
main= stable, live-ready code.- Feature branches for each new change.
- Merge when tested.
Pushing to GitHub
- Create a free account on GitHub and create a new repository (empty, no README if you already have files).
- Connect your local repo:
bash
git remote add origin https://github.com/yourname/my-website.git
git branch -M main
git push -u origin main - From now on, after committing:
bash
git push - To get changes from collaborators:
bash
git pull
For secure authentication, GitHub uses personal access tokens or SSH keys instead of passwords — see SSH Keys vs Passwords.
Many hosts and platforms can deploy directly from Git, so pushing to your main branch updates your live site automatically.
Further reading: MDN Web Docs learning area
Key Takeaways: Git for Beginners
- Git saves snapshots of your project so you can undo mistakes and collaborate.
- Learn the core loop:
git add→git commit→git push. - Use branches for new features and merge when ready.
- Use
.gitignoreand never commit secrets. - GitHub backs up your code and can power deployments.

