0% found this document useful (0 votes)
52 views4 pages

Mastering Git & GitHub for Juniors

This document is a comprehensive guide for junior developers on mastering Git, GitHub, and version control workflows. It covers the importance of version control, core Git concepts, common commands, GitHub features, practical workflows, best practices, and advanced commands. Additionally, it includes a 30-day learning roadmap, troubleshooting tips, and references for further reading.

Uploaded by

mrfrontman782
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views4 pages

Mastering Git & GitHub for Juniors

This document is a comprehensive guide for junior developers on mastering Git, GitHub, and version control workflows. It covers the importance of version control, core Git concepts, common commands, GitHub features, practical workflows, best practices, and advanced commands. Additionally, it includes a 30-day learning roadmap, troubleshooting tips, and references for further reading.

Uploaded by

mrfrontman782
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Git, GitHub & Version Control — A Senior Dev's

Curated Guide for Juniors


Curated, practical, and battle-tested — everything you need to master Git, GitHub and version control
workflows.

Generated: 2025-09-24 [Link] UTC

1. Why Version Control Matters


Version control records changes to files over time so you can recall specific versions later. It enables
collaboration, traceability, and safe experimentation (branches) while serving as a project time
machine. Use it for code, config, and any files you must track.

2. Git — The Tool


Git is a distributed version control system used locally and designed for speed and flexibility. Core
concepts: - Repository (repo): a project tracked by Git. - Commit: a snapshot with a message and
metadata (author, timestamp). - Branch: a movable pointer to a commit used for parallel development. -
HEAD: the current checked-out commit/branch. - Staging area (index): where you prepare changes
before committing.
Common Git commands (play these until they become reflex):
# Initialize or clone
git init # create a repo locally
git clone <url> # copy a remote repo locally

# Make changes and record them


git status # see changed files
git add <file> # stage changes
git add . # stage all
git commit -m "msg" # create a commit

# Inspect history
git log # detailed history (press q to exit pager)
git log --oneline --graph --decorate --all # compact graph view

# Branches & merging


git branch # list branches
git checkout -b feature # create & switch to a branch
git checkout feature # switch branch
git merge feature # merge feature into current branch
git rebase master # move commits (advanced; be careful)

# Undo & restore


git restore <file> # discard working changes
git restore --source=<hash> <file> # restore file from a commit
git reset --hard <hash> # move branch pointer (destructive)
git revert <hash> # create a new commit that undoes a commit

# Sharing
git remote add origin <url>
git push -u origin master # push branch to remote
git pull # fetch + merge remote changes

3. GitHub — The Platform


GitHub is a cloud-hosted service for Git repositories that provides collaboration features (issues, PRs,
code review, actions), remote backups, and community hosting. It integrates with CI/CD, project
boards, and package registries.

4. Practical Workflows (Senior-approved)


A. Feature-branch workflow (recommended for teams): - Create a branch for each task: git checkout -b
feat/xxx - Commit small, focused changes with clear messages - Push the branch and open a Pull
Request (PR) for review - After review, merge to main/master (use merge or squash strategy) B.
Trunk-based basics: - Keep main always deployable; commit small changes and use short-lived
branches. C. Releasing: - Create annotated tags for releases: git tag -a v1.2.0 -m "Release v1.2.0"

5. Undoing safely in shared repos


- If commit NOT pushed yet: git reset --hard HEAD~1 (rewrites local history) - If commit already
pushed/shared: use git revert to create a reversing commit (keeps history intact) - To recover a file from
a past commit: git checkout -- path/to/file (or git restore --source= path/to/file)

6. Best Practices & Senior Tips


- Use clear, imperative commit messages: "Add login form", "Fix NPE in user service". - Commit often,
but keep commits atomic and focused. - Use .gitignore to avoid tracking build artifacts, secrets, and OS
files. - Add your SSH key to GitHub and use SSH for authentication (or set up credential manager). -
Protect main/master with branch protection rules and require PR reviews. - Learn and practice 'git
rebase' locally but avoid rewriting published history. - Use 'git bisect' to find a commit that introduced a
bug when necessary.

7. Advanced Commands & When to Use Them


git stash # stash away local changes to get a clean working tree
git cherry-pick <hash> # apply a single commit from elsewhere
git reflog # find lost commits (your safety net)
git submodule add <url> # include another repo in this repo (use sparingly)
git worktree add ../wt # have multiple working copies of same repo

8. Learning Roadmap & Hands-on Exercises


Practice plan for the next 30 days: 1. Day 1–3: Basic workflow (init, add, commit, log, status, push/pull).
2. Day 4–7: Branching & merging; practice feature branches and resolve simple conflicts. 3. Day 8–12:
Remote collaboration: forks, PRs, code review. 4. Day 13–18: Rebase vs merge experiments on
throwaway repos. 5. Day 19–24: Revert, reset, reflog, stash, bisect exercises. 6. Day 25–30: Create a
real project, protect main, CI with GitHub Actions. Resources to read and reference are listed in the
next section.

9. Quick Reference: Common Problems & Fixes


- "Author identity unknown" -> set git config [Link] and [Link]
- "Merge conflicts" -> edit files, git add resolved files, git commit
- "Accidentally committed secrets" -> rotate secrets immediately; remove from history with gi
- "I rewrote history and pushed" -> coordinate with team; they must re-clone or force-reset c

10. References (curated authoritative sources)


- Official Git documentation & Pro Git book: [Link] and
[Link]
- GitHub Docs (Get started & Repositories): [Link] and
[Link]
- freeCodeCamp guides on Git & GitHub:
[Link]
- MDN — Version control (learning web development):
[Link]
- The Odin Project — Git Basics: [Link]
- W3Schools Git tutorial (quick reference): [Link]
Appendix A — Cheatsheet (one-page)
Init / clone:
git init
git clone <url>

Stage & commit:


git status
git add <file>
git commit -m "message"

Branches:
git checkout -b feature/x
git branch
git checkout main
git merge feature/x

Cancel / restore:
git restore <file>
git restore --source=<hash> <file>
git reset --hard <hash>
git revert <hash>

Share:
git remote add origin <url>
git push -u origin main
git pull

You might also like