Introduction to Git & GitHub
Understand the difference between Git and GitHub, how local and remote repositories work together, and the basic command flow teams use every day.
Simple Explanation (ELI5)
Git is the engine on your laptop that tracks your code history. GitHub is the online platform where teams share that history, review changes, and collaborate. Think of Git as your local notebook and GitHub as the shared team workspace.
Technical Explanation
Git is a distributed version control system. GitHub is a remote hosting and collaboration platform built around Git repositories. Typical workflow: clone remote repo, create local commits, push branch to GitHub, open pull request, run checks, merge to main branch.
Git vs GitHub
| Aspect | Git | GitHub |
|---|---|---|
| Type | VCS tool | Hosting + collaboration platform |
| Runs where | Local machine | Cloud web service |
| Primary function | Track file history | PRs, code review, issues, actions |
| Offline usage | Yes | No (needs network) |
| Core commands | commit, branch, merge | pull request, review, checks |
Visual: Local to Remote Flow
(Git)
(remote)
Basic Git Commands
# Clone repository from GitHub git clone https://github.com/org/project.git cd project # Create branch git checkout -b feature/login-page # Commit work git add . git commit -m "Add login page layout" # Push branch to GitHub git push -u origin feature/login-page # Update local branch with latest main git checkout main git pull origin main # Switch back to feature and rebase git checkout feature/login-page git rebase main
Real Team Workflow
- Developer creates feature branch from main.
- Local commits with small logical changes.
- Push branch to GitHub and open pull request.
- CI checks run (tests/lint/security).
- Teammates review and request changes.
- After approval, PR is merged to main.
- Release pipeline deploys from main.
Debugging Scenarios
- Push rejected: Remote has new commits. Run
git pull --rebase origin main, resolve conflicts, push again. - Wrong remote URL: Verify with
git remote -vand fix usinggit remote set-url origin .... - Authentication errors: Use GitHub PAT/SSH key; password auth for Git over HTTPS is deprecated.
- Detached HEAD confusion: Checkout a branch name before committing, or create one from current state.
Real-world Use Case
A distributed team across three time zones uses GitHub pull requests as async communication. Every feature includes description, screenshots, and linked issue. Even with no overlap in working hours, code quality remains high due to predictable review workflow and CI gates.
Interview Questions
Beginner
Git is a version control tool; GitHub is a platform for hosting and collaborating on Git repositories.
Downloads a full copy of a remote repository and its history to your local machine.
The default alias name for your primary remote repository.
To isolate work safely and avoid directly destabilizing main.
A proposal to merge branch changes into another branch, with review and checks.
Intermediate
It keeps commit history linear and reduces merge conflict complexity.
git push -u origin branch links local branch to remote branch for shorter future commands.
HTTPS usually uses PAT tokens; SSH uses keypairs and avoids repeated token prompts.
Contributors fork repo to personal namespace, push changes there, then open PR to upstream repo.
They enforce checks/reviews and prevent direct unsafe pushes to critical branches.
Scenario-based
Inspect CI logs, reproduce locally, fix issue, push update, and re-run checks.
Recover lost commits from reflog, restore branch state, and enforce protected branch policy.
Create hotfix branch from main, implement minimal fix, fast-track PR review, merge and tag release.
Use git remote -v, fetch upstream, rebase feature from upstream/main, push to origin.
Point to README, contributing guide, issue labels, and a “good first issue” branch workflow.
Summary
Git and GitHub are complementary: Git manages code history, GitHub enables team workflows around that history. Mastering both is essential for professional software collaboration.