Git & GitHub for beginners
Save versions of your code, work with a team and show your projects to recruiters — Git and GitHub explained step by step.
Why every company asks for Git
Definition: Version control is a system that records changes to files over time so you can recall specific versions; Git is a distributed version control system in which every developer has the full history locally.
How it works: You stage changes (git add) and record snapshots (git commit), each identified by a hash. Branches are lightweight pointers to commits, so you can develop features in parallel and merge them. Remotes (GitHub) let teams share history with push and pull.
Example: You can see who changed a line, when and why, and roll back a bad change.
🧒 In simple words
Git keeps a history of every change to your code, so you can go back in time and work with others without overwriting each other. GitHub is a website that stores Git projects online — and it doubles as your portfolio for recruiters.
Install and set up (once)
git --version
git config --global user.name "Asha Reddy"
git config --global user.email "[email protected]"git version 2.45.0
The everyday cycle
| Step | Command | What it does |
|---|---|---|
| 1 | git init | start tracking a folder |
| 2 | git status | see what changed |
| 3 | git add . | choose the changes to save |
| 4 | git commit -m "Add login page" | save a snapshot with a message |
| 5 | git push | upload to GitHub |
| 6 | git pull | download your team's changes |
A good commit message says what changed in the present tense: "Fix search typo", not "changes".
Put a project on GitHub
- On github.com click New repository, give it a name, keep it public.
- In your project folder:
git init
git add .
git commit -m "First version"
git branch -M main
git remote add origin https://github.com/your-name/project.git
git push -u origin mainTo https://github.com/your-name/project.git * [new branch] main -> main branch 'main' set up to track 'origin/main'.
Branches — work without breaking main
Definition: A branch is an independent line of development. Merging integrates the changes of one branch into another. A pull request is a GitHub feature for proposing a merge so others can review and discuss it first.
How it works: Merges can be fast-forward (just move the pointer) or create a merge commit; conflicting edits to the same lines must be resolved manually. Rebase replays commits on top of another branch for a linear history.
Example: Build a login feature on feature/login, open a PR, get it reviewed, merge into main.
🧒 In simple words
git checkout -b new-feature # make and switch to a branch
# …edit, add, commit…
git checkout main
git merge new-featureSwitched to a new branch 'new-feature' … Updating 3f2a1c0..9b7e4d2 Fast-forward login.html | 24 ++++++++++++
On teams you open a pull request on GitHub instead of merging yourself, so someone reviews your code first.
Fixing common mistakes
| Problem | Fix |
|---|---|
| Wrong commit message | git commit --amend -m "Better message" |
| Undo changes to a file | git restore file.py |
| Unstage a file | git restore --staged file.py |
| Merge conflict | open the file, keep the right lines, delete the <<<< ==== >>>> markers, add + commit |
Make your GitHub recruiter-ready
- Pin your 3 best projects.
- Every project has a README: what it does, a screenshot, how to run it, tech used.
- Commit regularly — a green contribution graph shows consistency.
Interview questions
- Git vs GitHub? Git is the tool; GitHub hosts Git projects online.
- merge vs rebase? merge keeps both histories with a merge commit; rebase replays your commits on top for a straight line.
- What is a pull request? A request to merge your branch after review.
- git fetch vs git pull? fetch downloads changes; pull = fetch + merge.