Skip to content

Commit 7ddacf3

Browse files
authored
Merge pull request #238 from codeharborhub/dev-1
added git docs
2 parents 9495885 + 14ecc9c commit 7ddacf3

File tree

16 files changed

+1063
-2
lines changed

16 files changed

+1063
-2
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"label": "Collaboration",
3+
"position": 5,
4+
"link": {
5+
"type": "generated-index",
6+
"title": "Collaboration & Open Source",
7+
"description": "Learn the social side of coding. Master Pull Requests, solve conflicts, and contribute to global projects at CodeHarborHub. Discover how to collaborate effectively, manage branches, and navigate the world of open-source development. Join us on this journey to become a confident collaborator in the coding community."
8+
}
9+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
---
2+
title: "Cloning a Repository"
3+
sidebar_label: "2. Cloning"
4+
sidebar_position: 2
5+
description: "Learn how to download a repository from GitHub to your local computer to start coding. This is the essential next step after forking a project and is crucial for contributing to open-source software. Master the cloning process to bring code from the cloud to your machine and begin your development journey."
6+
tags: ["git", "github", "cloning", "open-source", "contributing"]
7+
keywords: ["git", "github", "cloning", "open-source", "contributing"]
8+
---
9+
10+
Once you have a repository on GitHub (either your own or a **Fork** you made), the next step is to bring that code onto your physical computer. This process is called **Cloning**.
11+
12+
When you clone a repository, you aren't just downloading the files; you are downloading the **entire project history** and setting up a connection between your computer and the cloud.
13+
14+
15+
## What happens during a Clone?
16+
17+
Unlike a simple "Download ZIP," `git clone` does three things automatically:
18+
1. **Creates a folder** with the project name.
19+
2. **Downloads every version** of every file in the project's history.
20+
3. **Sets up a Remote** called `origin`, which points back to GitHub so you can push and pull changes later.
21+
22+
## How to Clone a Project
23+
24+
To clone a repository, you need its **URL**. You can find this on the main page of any GitHub repository.
25+
26+
### Step 1: Get the URL
27+
1. Go to the repository on GitHub.
28+
2. Click the green **`<>` Code** button.
29+
3. Copy the **HTTPS** URL (it looks like `https://github.com/user/repo.git`).
30+
31+
### Step 2: Run the Command
32+
Open your terminal (or Git Bash) and type `git clone` followed by the URL you copied:
33+
34+
```bash
35+
git clone https://github.com/codeharborhub/tutorial.git
36+
```
37+
38+
### Step 3: Enter the Project
39+
40+
After the download finishes, you must move into the new folder before you can start working:
41+
42+
```bash
43+
cd tutorial
44+
```
45+
46+
## Comparison: Clone vs. Download ZIP
47+
48+
| Feature | Git Clone | Download ZIP |
49+
| :--- | :--- | :--- |
50+
| **Files** | Yes | Yes |
51+
| **History** | Yes (Every commit ever made) | No (Only current files) |
52+
| **Updates** | Easy (`git pull`) | Must download whole ZIP again |
53+
| **Contribution**| Ready to Push/PR | Not connected to Git |
54+
55+
## Common Use Cases
56+
57+
| Scenario | What to do? |
58+
| :--- | :--- |
59+
| **Joining a Team** | Get the project URL from your lead and `git clone` it. |
60+
| **Switching PCs** | `git clone` your own repo to your new laptop. |
61+
| **Learning Open Source** | Find a cool repo, `fork` it, then `clone` your fork. |
62+
63+
## Cloning with VS Code
64+
65+
If you prefer using a visual tool instead of the terminal, you can clone directly inside **Visual Studio Code**:
66+
67+
1. Open VS Code.
68+
2. Press `Ctrl + Shift + P` (or `Cmd + Shift + P` on Mac).
69+
3. Type **Git: Clone** and press Enter.
70+
4. Paste the GitHub URL and choose a folder on your computer. VS Code will handle the cloning process for you!
71+
72+
## Important Note for Beginners
73+
74+
**Only clone once.** A common mistake is running `git clone` every time you want to work on a project.
75+
76+
* Use `git clone` the **first time** you get the project.
77+
* Use `git pull` every time **after that** to get the latest updates.
78+
79+
:::tip
80+
By default, Git clones the project into a folder named after the repository. If you want to name the folder something else, just add the name at the end:
81+
`git clone https://github.com/user/repo.git my-custom-folder-name`
82+
:::
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
---
2+
title: "Forking a Repository"
3+
sidebar_label: "1. Forking"
4+
sidebar_position: 1
5+
description: "Learn how to create your own personal copy of an existing project on GitHub to experiment and contribute. This is the essential first step in your journey to becoming a proficient GitHub user and open-source contributor."
6+
tags: ["git", "github", "forking", "open-source", "contributing"]
7+
keywords: ["git", "github", "forking", "open-source", "contributing"]
8+
---
9+
10+
In the world of Open Source, you often find amazing projects that you want to improve or use as a starting point for your own work. However, you don't have permission to edit the original code directly.
11+
12+
This is where **Forking** comes in. At **CodeHarborHub**, we consider forking the first step toward becoming a true Open Source contributor.
13+
14+
:::info
15+
If you are new to GitHub, forking is the best way to get your own copy of a project that you can experiment with and eventually contribute back to the original author.
16+
:::
17+
18+
## What is a Fork?
19+
20+
A **Fork** is a complete copy of a repository that is managed under **your** GitHub account instead of the original author's. It allows you to freely make changes without affecting the original project. You can then propose your changes to the original author through a **Pull Request**.
21+
22+
### The "Notebook" Analogy
23+
24+
Imagine your teacher has a master notebook with a great science experiment.
25+
* You can't write in the teacher's notebook.
26+
* You **Fork** it by taking the notebook to a photocopier.
27+
* Now you have your own copy. you can change the steps, add drawings, or fix typos without changing the teacher's master version.
28+
29+
## How to Fork a Project
30+
31+
Forking is a "one-click" process that happens entirely on the GitHub website.
32+
33+
1. **Find the Project:** Navigate to the repository you want to fork (e.g., `github.com/codeharborhub/git-tutorial`).
34+
2. **Locate the Button:** In the top-right corner of the page, click the **Fork** button.
35+
3. **Configure (Optional):** GitHub will ask if you want to copy just the `main` branch or all branches. For beginners, "main branch only" is usually best.
36+
4. **Create:** Click **Create Fork**.
37+
38+
## Why do we Fork? (Use Cases)
39+
40+
| Use Case | Description |
41+
| :--- | :--- |
42+
| **Contributing** | You found a bug in a project and want to fix it. You fork the repo, fix the bug in your copy, and then ask the owner to pull your fix. |
43+
| **Experimentation** | You want to try a new feature but don't want to break the original project's stable code. |
44+
| **Starting Point** | You found a "Boilerplate" or "Template" project that you want to use as the foundation for your own new app. |
45+
46+
## Forking vs. Cloning
47+
48+
It is very common for beginners to confuse these two. Here is the professional breakdown:
49+
50+
```mermaid
51+
graph TD
52+
A[Original Project] -- "Fork (Cloud)" --> B[Your GitHub Fork]
53+
B -- "Clone (Local)" --> C[Your Computer]
54+
C -- "Commit & Push" --> B
55+
```
56+
57+
* **Forking** happens on the **GitHub Server**. It creates a copy on the cloud.
58+
* **Cloning** happens on **Your Machine**. It downloads the code so you can work offline.
59+
60+
## Keeping Your Fork Up-to-Date
61+
62+
One challenge with forking is that the original project keeps moving forward. If the original author adds a new feature, your fork won't have it automatically.
63+
64+
To sync your fork, you can use the **Sync Fork** button on the GitHub interface of your repository:
65+
66+
1. Go to your forked repo on GitHub.
67+
2. Click **Sync fork**.
68+
3. Click **Update branch**.
69+
70+
:::tip
71+
Forking is a "Public" action. Everyone can see that you forked a project, and it often shows up on your profile as a sign that you are active in the developer community!
72+
:::

absolute-beginners/git-github-beginner/collaboration/index.mdx

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
---
2+
title: "Open Source Licenses"
3+
sidebar_label: "7. OSS Licenses"
4+
sidebar_position: 7
5+
description: "Understand the legal side of Open Source and learn how to choose the right license for your projects. This is crucial for protecting your work and allowing others to use and contribute to it. Master the art of licensing to ensure your code can be shared and built upon by the community while safeguarding your rights as a creator."
6+
tags: ["git", "github", "open source licenses", "collaboration", "legal", "protection", "sharing"]
7+
keywords: ["git", "github", "open source licenses", "collaboration", "legal", "protection", "sharing"]
8+
---
9+
10+
Making a repository "Public" on GitHub does not automatically mean people can use, modify, or share your code. Without a **License**, your code is technically under "Exclusive Copyright," meaning you own it and no one else can touch it.
11+
12+
At **CodeHarborHub**, we believe in sharing. A license is a simple text file that tells the community exactly what they are allowed to do with your work.
13+
14+
:::info
15+
Think of a license like the "Terms and Conditions" for your code. It sets the rules for how others can use, modify, and share your project. Without it, your code is like a locked treasure chest that no one can open.
16+
:::
17+
18+
## Why Do You Need a License?
19+
20+
1. **Permission:** It legally allows others to "Fork" and "Clone" your project.
21+
2. **Protection:** Most licenses include a "No Warranty" clause, meaning you aren't responsible if your code breaks someone else's computer.
22+
3. **Contribution:** Professional developers and companies will *never* use or contribute to a project that doesn't have a clear license.
23+
24+
## The "Big Three" Licenses
25+
26+
There are hundreds of licenses, but in the professional world, 90% of projects use one of these three:
27+
28+
| License | Type | Permission Level | Summary |
29+
| :--- | :--- | :--- | :--- |
30+
| **MIT** | **Permissive** | High | "Do whatever you want, just keep my name on it." |
31+
| **Apache 2.0** | **Permissive** | High | Similar to MIT, but gives extra protection against patent lawsuits. |
32+
| **GNU GPLv3** | **Copyleft** | Medium | "You can use my code, but your project MUST also be open source." |
33+
34+
## Which One Should You Choose?
35+
36+
### 1. The MIT License (Recommended for Beginners)
37+
This is the most popular license at **CodeHarborHub**. It is short, simple, and very "friendly." It allows people to use your code in private, commercial, and open-source projects.
38+
* **Use it if:** You want the most people possible to use your code.
39+
40+
### 2. The Apache License 2.0
41+
This is the standard for large-scale professional projects (like Android or Kubernetes).
42+
* **Use it if:** You are building a serious library or tool and want to be professional about patents.
43+
44+
### 3. The GNU GPLv3
45+
This is a "Restrictive" or "Copyleft" license. If someone uses your GPL code, they are legally forced to make their entire project open source too.
46+
* **Use it if:** You want to ensure that no one ever takes your code and makes a "secret" paid version of it.
47+
48+
## How to Add a License to Your Repo
49+
50+
GitHub makes this incredibly easy. You don't need a lawyer!
51+
52+
1. Go to your repository on GitHub.
53+
2. Click **Add file** > **Create new file**.
54+
3. Type `LICENSE` (all caps) as the filename.
55+
4. A button will appear: **"Choose a license template"**. Click it.
56+
5. Select a license (like MIT), click **Review and submit**, and commit the file.
57+
58+
## What Happens if I Don't Choose One?
59+
60+
If you have a public repo with **no license**:
61+
* People can read your code.
62+
* People can fork your code (because GitHub's Terms of Service allow it).
63+
* **But**, people cannot legally use your code in their own apps, and they cannot contribute back to you safely.
64+
65+
> **Moral of the story:** If you want people to use your work, always add an **MIT License**.
66+
67+
:::tip
68+
Not sure which one fits your specific vibe? Check out [choosealicense.com](https://choosealicense.com/). It's a simple tool created by GitHub to help you pick the perfect legal protection for your code.
69+
:::
70+
71+
Now that you understand the legal side of sharing your code, you're ready to make your projects truly open source. In the next chapter, we'll dive into how to keep your fork in sync with the original project using the concept of "Upstream." This is essential for contributing to open-source projects and ensuring your code is built on the most recent version of the project. Let's get started!s
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
---
2+
title: "Pulling and Pushing Changes"
3+
sidebar_label: "4. Pull & Push"
4+
sidebar_position: 4
5+
description: "Learn the daily workflow of syncing your local code with GitHub to keep your project up-to-date. Master the essential commands for pulling changes from the remote repository and pushing your work to share with your team. This is a crucial skill for collaborating effectively in any software development project."
6+
tags: ["git", "github", "pull", "push", "syncing", "collaboration"]
7+
keywords: ["git", "github", "pull", "push", "syncing", "collaboration"]
8+
---
9+
10+
In a collaborative environment like **CodeHarborHub**, code is constantly moving between your computer (Local) and GitHub (Remote). To stay in sync with your team, you must master the two most frequent actions in a developer's day: **Pulling** and **Pushing**.
11+
12+
:::important
13+
Pulling and Pushing are the heartbeat of any project. They keep everyone on the same page and ensure that your work is shared with the world. Master these commands to become a true collaborator at **CodeHarborHub**.
14+
:::
15+
16+
## The "Daily Cycle" Concept
17+
18+
Think of a shared **Google Doc**.
19+
* **Pulling** is like refreshing the page to see what your friends wrote while you were away.
20+
* **Pushing** is like hitting "Save" so your friends can see what *you* just wrote.
21+
22+
## 1. Pulling Changes (`git pull`)
23+
24+
**When to use it:** Every morning before you start coding, and every time a teammate tells you they've finished a feature.
25+
26+
When you run `git pull`, two things happen:
27+
1. Git **Fetches** the new data from GitHub.
28+
2. Git **Merges** that data into your local files.
29+
30+
```bash
31+
# Get the latest code from the 'main' branch on GitHub
32+
git pull origin main
33+
```
34+
35+
## 2. Pushing Changes (`git push`)
36+
37+
**When to use it:** After you have "Staged" and "Committed" your work locally and you are ready to share it with the world.
38+
39+
```bash
40+
# Send your 'feat-login' branch to GitHub
41+
git push origin feat-login
42+
```
43+
44+
## The "Golden Workflow"
45+
46+
At an **Industrial Level**, we follow this 4-step loop to avoid errors and conflicts:
47+
48+
| Step | Command | Why? |
49+
| :--- | :--- | :--- |
50+
| **1. Update** | `git pull origin main` | Start with the latest version of the project. |
51+
| **2. Code** | *(Work in VS Code)* | Make your magic happen. |
52+
| **3. Save** | `git add .` & `git commit` | Create your local "Save Point." |
53+
| **4. Share** | `git push origin your-branch` | Upload your work to the cloud. |
54+
55+
## Dealing with "Rejected" Pushes
56+
57+
Sometimes, you try to `git push` and see a scary red error message: **[rejected]**.
58+
59+
**Why did this happen?**
60+
This happens because a teammate pushed code to GitHub *after* your last pull. GitHub won't let you push your work because it would overwrite your teammate's work.
61+
62+
**The Fix:**
63+
64+
1. **Pull first:** `git pull origin main`
65+
2. **Resolve any conflicts** (if they exist).
66+
3. **Push again:** `git push origin main`
67+
68+
## The `fetch` Alternative
69+
70+
If you want to see what your teammates did **without** merging it into your files yet, use:
71+
72+
```bash
73+
git fetch origin
74+
```
75+
76+
This downloads the data but doesn't change your code. It's like "Previewing" the changes before you commit to them.
77+
78+
:::tip
79+
Always **Pull before you Push**. This simple habit will save you from 90% of the merge conflicts you might face at **CodeHarborHub**.
80+
:::

0 commit comments

Comments
 (0)