Skip to content

Commit 7893088

Browse files
committed
Tips and Tricks
Signed-off-by: https://github.com/Someshdiwan <someshdiwan369@gmail.com>
1 parent d9feaf6 commit 7893088

3 files changed

Lines changed: 304 additions & 0 deletions

File tree

Tips And Tricks/Github.txt

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
Perfect — here’s a visual ASCII diagram showing how forks, remotes, branches, and PRs fit together. This is the “map in your head” for push/pull/rebase.
2+
3+
4+
5+
GitHub Fork Workflow — Visual Map
6+
7+
┌─────────────────────────────────────────┐
8+
│ Original Repo (upstream) │
9+
│ https://github.com/OriginalOwner/repo │
10+
│ │
11+
│ main (branch) ────────────────────┐ │
12+
└─────────────────────────────────────┘ │
13+
│ Pull Request (PR)
14+
15+
┌───────────────────────────────────────────────┐ ┌─────────────────────────────────────┐
16+
│ Your Fork (origin) │ │ Upstream repo (maintainer merges) │
17+
│ https://github.com/YourUser/repo │ │ https://github.com/OriginalOwner │
18+
│ │ │ │
19+
│ main (branch, copy of upstream main) │◄─────┤ main (branch) │
20+
│ ▲ │ │ │
21+
│ │ (keep updated via merge/rebase) │ │ │
22+
│ │ │ │
23+
│ feature-branch │─────►│ main (after PR merged) │
24+
│ │ │ │ │
25+
│ │ (your commits) │ │ │
26+
└───────────────────────────────────────────────┘ └─────────────────────────────────────┘
27+
28+
29+
30+
31+
How commands map onto this diagram
32+
33+
1. Set up remotes
34+
35+
git clone https://github.com/YourUser/repo.git
36+
cd repo
37+
git remote add upstream https://github.com/OriginalOwner/repo.git
38+
39+
• origin = your fork
40+
• upstream = original repo
41+
42+
43+
44+
2. Keep your fork’s main updated
45+
46+
git checkout main
47+
git fetch upstream
48+
git merge upstream/main # OR git rebase upstream/main
49+
git push origin main
50+
51+
52+
53+
54+
3. Create a feature branch for your change
55+
56+
git checkout -b feature-branch
57+
# make edits
58+
git add .
59+
git commit -m "Your change"
60+
git push origin feature-branch
61+
62+
63+
64+
65+
4. Open Pull Request
66+
• Compare: YourUser:feature-branch → OriginalOwner:main
67+
68+
69+
70+
5. If maintainers change main while your PR is open
71+
72+
Rebase your branch:
73+
74+
git checkout feature-branch
75+
git fetch upstream
76+
git rebase upstream/main
77+
# resolve conflicts if any
78+
git push origin feature-branch --force-with-lease
79+
80+
81+
82+
83+
👉 This diagram shows the two “worlds”: your fork (origin) and the official repo (upstream). Your feature-branch is only in your fork until you open a PR. After merge, the changes live in upstream’s main.
84+
85+
86+
87+
Would you like me to also show a commit graph diagram (with merge vs rebase paths) so you can see how history looks in both cases?

Tips And Tricks/GithubWorking.txt

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
Yes, we can definitely turn this into a clean anonymous one-page GitHub/Git workflow cheat sheet — no JetBrains, no school references, just the structure + universal commands.
2+
3+
Here’s a refined version:
4+
5+
6+
7+
GitHub/Git Pro Workflow Cheat Sheet
8+
9+
10+
11+
1) GitHub Hierarchy
12+
13+
GitHub (service)
14+
└─ Account (User or Organization)
15+
├─ Repositories (repos) ← projects
16+
│ ├─ Default branch (main/master) ← main production line
17+
│ ├─ Feature branches ← short-lived work
18+
│ ├─ Release branches / tags ← versioned snapshots
19+
│ ├─ Files & folders (src/, docs/, .github/, etc.)
20+
│ ├─ Commits ← saved history
21+
│ ├─ Pull Requests (PRs) ← propose merging changes
22+
│ ├─ Issues ← bugs, tasks, discussions
23+
│ ├─ Actions / CI workflows ← automation, builds, tests
24+
│ └─ Settings ← permissions, protections
25+
├─ Forks (personal copies of repos)
26+
│ ├─ origin = your fork remote
27+
│ └─ upstream = original repo
28+
└─ Organizations (group accounts)
29+
├─ Repositories
30+
├─ Teams
31+
└─ Policies (branch protection, CI required)
32+
33+
34+
35+
36+
2) Core Concepts
37+
• Clone → copy repo from remote to local.
38+
• Fork → personal remote copy on GitHub.
39+
• Remote → pointer to a repo (origin, upstream).
40+
• Branch → independent development line.
41+
• Commit → snapshot with a message.
42+
• Push → send commits to remote.
43+
• Pull → fetch + merge (or rebase).
44+
• Fetch → update remote refs without merging.
45+
• Merge → combine changes.
46+
• Rebase → reapply commits on new base.
47+
• PR → request to merge changes.
48+
• Squash → combine commits into one.
49+
• Conflict → manual resolution needed when code overlaps.
50+
51+
52+
53+
3) Common Workflows
54+
55+
A — Contribute via Fork
56+
57+
git clone https://github.com/YourUser/repo.git
58+
cd repo
59+
git remote add upstream https://github.com/OriginalOwner/repo.git
60+
61+
git checkout -b feature-branch
62+
# make changes
63+
git add .
64+
git commit -m "Describe your change"
65+
git push origin feature-branch
66+
67+
Open PR: YourUser:feature-branch → OriginalOwner:main
68+
69+
70+
71+
B — Sync fork with upstream
72+
73+
git checkout main
74+
git fetch upstream
75+
git merge upstream/main # or rebase: git rebase upstream/main
76+
git push origin main
77+
78+
79+
80+
81+
C — Rebase workflow (clean history)
82+
83+
git checkout feature-branch
84+
git fetch upstream
85+
git rebase upstream/main
86+
# resolve conflicts if any
87+
git push origin feature-branch --force-with-lease
88+
89+
90+
91+
92+
D — Squash commits
93+
94+
git checkout feature-branch
95+
git rebase -i HEAD~3 # squash last 3 commits
96+
git push origin feature-branch --force-with-lease
97+
98+
99+
100+
101+
E — Undo mistakes
102+
103+
git rebase --abort # stop rebase
104+
git reset --hard origin/feature-branch # reset local to remote
105+
git revert <commit-hash> # undo specific commit
106+
107+
108+
109+
110+
4) Pull Request Etiquette
111+
• Title: concise & descriptive.
112+
• Description: explain clearly, follow template.
113+
• Keep branch focused: one logical change.
114+
• Small commits → easier review.
115+
• Squash noisy commits.
116+
• Keep “Allow edits by maintainers” ON.
117+
• Fix CI/test issues before asking review.
118+
119+
120+
121+
5) Mini Visual Flow
122+
123+
Fork repo → Clone → Create branch → Commit → Push → Open PR
124+
→ Review → Address comments → Merge into upstream
125+
126+
127+
128+
129+
This way, you’ve got the hierarchy, commands, and etiquette in one page.
130+
131+
Would you like me to make a visual ASCII diagram of remotes/branches (origin vs upstream, main vs feature branch) so you can instantly see where push/pull/rebase happen?

Tips And Tricks/git.txt

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
Nice — here’s the commit graph diagram you asked for. This shows how your history looks depending on whether you merge or rebase.
2+
3+
4+
5+
A) Merge workflow (preserves full branch graph)
6+
7+
Upstream main: A──B──C───────────────┐
8+
9+
Your branch: A──B──C──D──E─────────┴─M
10+
11+
Merge commit (M)
12+
13+
• You branched from commit C.
14+
• You added commits D and E.
15+
• Upstream added commits after C.
16+
• When you git merge upstream/main, Git creates a merge commit (M) joining both histories.
17+
• History shows branching + merging — good for context but can look messy.
18+
19+
20+
21+
B) Rebase workflow (linear history, no merge commit)
22+
23+
Upstream main: A──B──C──F──G──H
24+
25+
Your branch after rebase: D'──E'
26+
27+
• Same start at commit C.
28+
• Upstream added commits F, G, H.
29+
• When you git rebase upstream/main, your commits (D, E) are replayed on top of the new tip H, becoming D' and E'.
30+
• Result: looks like you developed your feature after the latest upstream work — clean linear history.
31+
• Requires --force-with-lease when pushing, because commit hashes change.
32+
33+
34+
35+
C) Side-by-side: Merge vs Rebase
36+
37+
Merge history (graphy):
38+
39+
A──B──C───────────────F──G──H
40+
└──D──E──────────────┘
41+
42+
Rebase history (linear):
43+
44+
A──B──C──F──G──H──D'──E'
45+
46+
47+
48+
49+
D) When to use what
50+
• Merge →
51+
• If you want to preserve the “real” history (showing when branches diverged).
52+
• Safer for beginners (no rewriting commits).
53+
• Good for long-lived feature branches.
54+
• Rebase →
55+
• If you want a clean, straight line history.
56+
• Preferred in open-source PR workflows.
57+
• Requires confidence resolving conflicts & force-pushing.
58+
59+
60+
61+
E) Common commands
62+
63+
Merge workflow:
64+
65+
git checkout feature-branch
66+
git fetch upstream
67+
git merge upstream/main
68+
git push origin feature-branch
69+
70+
Rebase workflow:
71+
72+
git checkout feature-branch
73+
git fetch upstream
74+
git rebase upstream/main
75+
# fix conflicts if needed
76+
git push origin feature-branch --force-with-lease
77+
78+
79+
80+
81+
So: Merge = “historical diary” (records exactly what happened).
82+
Rebase = “rewrite the story” (makes it look like you developed cleanly on top).
83+
84+
85+
86+
Want me to also sketch a real-life example with commit hashes (like abc123, def456) so you can see how git log looks different between merge and rebase?

0 commit comments

Comments
 (0)