-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Expand file tree
/
Copy pathGitHub_Beginner_to_Pro.txt
More file actions
358 lines (232 loc) · 6.69 KB
/
GitHub_Beginner_to_Pro.txt
File metadata and controls
358 lines (232 loc) · 6.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
GITHUB FROM BEGINNER TO PRO
======================================================
1. First idea: what is Git and what is GitHub?
----------------------------------------------
Think about drawing.
* Git = your magic time machine notebook. It remembers every version of your drawing.
* GitHub = your online shelf where you store that notebook, share it, and work with friends.
So:
* Git works on your computer.
* GitHub works on the internet.
2. The 3 places your code lives
-------------------------------
Every project has 3 places:
1. Working folder: where you edit files now.
2. Staging area: files you pick for next save point.
3. Repository history: saved snapshots (commits).
Simple flow:
* edit file
* stage it (git add)
* save snapshot (git commit)
* send to GitHub (git push)
3. The 5 commands you use all the time
--------------------------------------
1. git status
* Shows what changed.
2. git add .
* Picks changed files for next save.
3. git commit -m "message"
* Saves a snapshot with a message.
4. git pull
* Gets latest changes from GitHub.
5. git push
* Sends your commits to GitHub.
If you only remember one daily routine, remember:
git pull -> edit -> git add . -> git commit -m "..." -> git push
4. What is a commit?
--------------------
A commit is a save point.
* It has an ID (like a fingerprint).
* It has author, time, and message.
* You can go back to it any time.
Good commit messages:
* Fix login bug when password has spaces
* Add evaluator model switch to gpt-5-mini
Bad commit messages:
* update
* changes
5. Branches (your safe playgrounds)
-----------------------------------
Branch = a separate line of work.
* main is the main road.
* Feature branch is side road.
Why branches are great:
* You can try new things safely.
* If experiment fails, main stays clean.
Typical branch flow:
1. git checkout -b feature/add-chat-ui
2. Make changes and commit.
3. Push branch: git push -u origin feature/add-chat-ui
4. Open Pull Request on GitHub.
5. Merge into main.
6. Pull Requests (PRs)
----------------------
PR = "Please review my work before we merge it."
A good PR has:
* clear title
* short summary (what and why)
* test notes (how you checked it)
* screenshots if UI changed
Keep PRs small. Small PRs are easier to review and safer.
7. Merge conflicts (when Git gets confused)
-------------------------------------------
Conflict means:
* You changed a line.
* Someone else changed same line.
* Git asks: "Which one should I keep?"
How to fix:
1. Pull latest changes.
2. Open conflicted file.
3. Pick correct code (or combine both).
4. git add <file>
5. git commit
6. git push
Conflicts are normal. Even pros get them.
8. How to see old versions
--------------------------
* git log --oneline --graph --decorate
See history.
* git show <commit_id>
See one commit details.
* git diff
See unsaved differences.
* git diff <old> <new>
Compare two versions.
9. Undo safely (super important)
--------------------------------
### Undo unstaged file edits
git restore <file>
### Unstage file
git restore --staged <file>
### Make a new commit that reverses old one
git revert <commit_id>
Beginner rule:
* Prefer git revert over risky history rewrites.
10. The .gitignore file
-----------------------
.gitignore tells Git what NOT to track.
Common things to ignore:
* .env
* .venv/
* __pycache__/
* big temporary files
Why:
* keep secrets safe
* keep repo small and clean
11. Secrets and safety
----------------------
Never commit:
* API keys
* passwords
* private tokens
Use:
* .env for local secrets
* GitHub Secrets for CI/CD and deployments
If secret is leaked:
1. Revoke/rotate key immediately.
2. Remove secret from code.
3. Commit fix.
12. GitHub Issues, Projects, Discussions
----------------------------------------
* Issues: bug reports and tasks.
* Projects: board to track work (To do, Doing, Done).
* Discussions: community Q and A.
Pro teams use all three.
13. Actions (automation robot)
------------------------------
GitHub Actions = robot that runs when you push.
Use it for:
* tests
* lint checks
* build
* deploy
Why pro teams love this:
* catches mistakes early
* keeps quality high
14. Releases and tags
---------------------
Tag = name for a specific commit (like v1.0.0).
Release = packaged version with notes.
Version pattern (SemVer):
* MAJOR.MINOR.PATCH
* Example: 2.3.1
Meaning:
* MAJOR: breaking change
* MINOR: new feature
* PATCH: bug fix
15. Forks vs clones
-------------------
* Clone: copy repo to your computer.
* Fork: copy someone else's repo to your GitHub account.
Open source flow:
1. Fork repo.
2. Clone your fork.
3. Create branch.
4. Commit changes.
5. Push to your fork.
6. Open PR to original repo.
16. Good habits that make you look pro
--------------------------------------
1. Commit often, but with meaningful messages.
2. Keep PRs small.
3. Pull before push.
4. Write README clearly.
5. Add tests for important logic.
6. Protect main branch.
7. Do code reviews kindly and clearly.
17. Fast daily checklist
------------------------
Before coding:
1. git pull
2. git status
After coding:
1. git status
2. git add .
3. git commit -m "clear message"
4. git push
Before sleeping:
1. Confirm changes are pushed.
2. Check PR status.
3. Check CI (Actions) is green.
18. Beginner mistakes and fixes
-------------------------------
Mistake: "I forgot to pull first"
* Fix: git pull --rebase then push.
Mistake: "I committed wrong file"
* Fix: git restore --staged <file> then recommit.
Mistake: "I broke main"
* Fix: create a revert commit fast.
Mistake: "My notebook outputs created huge diffs"
* Fix: clear outputs before commit if project expects clean notebooks.
19. 30 day learning plan (easy)
-------------------------------
Week 1:
* Learn status, add, commit, push, pull.
* Make 1 repo and 10 small commits.
Week 2:
* Learn branches and PRs.
* Open and merge at least 3 PRs.
Week 3:
* Learn conflicts and safe undo.
* Practice git diff, git show, git revert.
Week 4:
* Add GitHub Actions for lint and tests.
* Add releases and tags.
* Review one open source PR flow.
20. Tiny cheat sheet
--------------------
* New repo: git init
* Connect remote: git remote add origin <url>
* First push: git push -u origin main
* New branch: git checkout -b <branch>
* Switch branch: git checkout <branch>
* Show history: git log --oneline
21. Final simple story
----------------------
Git is your save button with memory.
GitHub is your online team notebook.
Branches are safe sandboxes.
Commits are save points.
PRs are "please check my homework".
Actions are robots checking homework.
If you keep code small, clear, and frequent, you will become very strong very fast.