|
| 1 | +--- |
| 2 | +sidebar_position: 6 |
| 3 | +title: "Git Setup & Your First Repo" |
| 4 | +sidebar_label: "6. Setup Guide" |
| 5 | +description: "Step-by-step instructions to install Git, configure your profile, and push your first project to GitHub." |
| 6 | +--- |
| 7 | + |
| 8 | +It’s time to stop reading and start doing! In this guide, we will transform your computer into a developer workstation. |
| 9 | + |
| 10 | +## Step 1: Install Git |
| 11 | + |
| 12 | +First, we need to get the Git engine running on your machine. |
| 13 | + |
| 14 | +<Tabs> |
| 15 | + <TabItem value="windows" label="🪟 Windows" default> |
| 16 | + |
| 17 | + 1. Download the **[Git for Windows](https://git-scm.com/download/win)** installer. |
| 18 | + 2. Run the `.exe` file. |
| 19 | + 3. **Important:** When asked about the "Default Editor," you can choose **Visual Studio Code**. |
| 20 | + 4. Keep all other settings as "Default" and click **Install**. |
| 21 | + |
| 22 | + </TabItem> |
| 23 | + <TabItem value="mac" label="🍎 macOS"> |
| 24 | + |
| 25 | + 1. Open your Terminal (Command + Space, type `Terminal`). |
| 26 | + 2. Type `git --version` and hit Enter. |
| 27 | + 3. If you don't have it, a popup will ask you to install **Xcode Command Line Tools**. Click **Install**. |
| 28 | + 4. Alternatively, if you use [Homebrew](https://brew.sh/), run: `brew install git`. |
| 29 | + |
| 30 | + </TabItem> |
| 31 | + <TabItem value="linux" label="🐧 Linux"> |
| 32 | + |
| 33 | + Open your terminal and run the command for your distribution: |
| 34 | + * **Ubuntu/Debian:** `sudo apt install git-all` |
| 35 | + * **Fedora:** `sudo dnf install git-all` |
| 36 | + |
| 37 | + </TabItem> |
| 38 | +</Tabs> |
| 39 | + |
| 40 | +## Step 2: Configure Your Identity |
| 41 | + |
| 42 | +Git needs to know who is making changes. Open your terminal (or **Git Bash** on Windows) and type these two lines: |
| 43 | + |
| 44 | +```bash |
| 45 | +git config --global user.name "Your Name" |
| 46 | +git config --global user.email "your-email@example.com" |
| 47 | +``` |
| 48 | + |
| 49 | +*Note: Use the same email address you plan to use for your GitHub account.* |
| 50 | + |
| 51 | +## Step 3: Create Your First Repository |
| 52 | + |
| 53 | +Let's create a "Hello World" project and track it with Git. |
| 54 | + |
| 55 | +### 1. Create a Folder |
| 56 | + |
| 57 | +```bash |
| 58 | +mkdir my-first-repo |
| 59 | +cd my-first-repo |
| 60 | +``` |
| 61 | + |
| 62 | +### 2. Initialize Git |
| 63 | + |
| 64 | +This creates a hidden `.git` folder. This is where the "Time Machine" lives! |
| 65 | + |
| 66 | +```bash |
| 67 | +git init |
| 68 | +``` |
| 69 | + |
| 70 | +### 3. Create a File |
| 71 | + |
| 72 | +Create a simple file named `hello.txt` and add some text to it. |
| 73 | + |
| 74 | +### 4. The Magic Sequence (Add & Commit) |
| 75 | + |
| 76 | +```bash |
| 77 | +# Add the file to the Staging Area |
| 78 | +git add hello.txt |
| 79 | + |
| 80 | +# Save the snapshot to the Local Repository |
| 81 | +git commit -m "feat: my very first commit" |
| 82 | +``` |
| 83 | + |
| 84 | +## Step 4: Connect to GitHub |
| 85 | + |
| 86 | +Now, let's put your code in the cloud so the world can see it. |
| 87 | + |
| 88 | +1. Go to **[GitHub.com](https://github.com)** and create a free account. |
| 89 | +2. Click the **+** icon in the top right and select **New Repository**. |
| 90 | +3. Name it `my-first-repo` and click **Create repository**. |
| 91 | +4. GitHub will give you a "Remote URL" (it looks like `https://github.com/your-username/my-first-repo.git`). |
| 92 | + |
| 93 | +**Run these commands in your terminal to link your computer to GitHub:** |
| 94 | + |
| 95 | +```bash |
| 96 | +# Link your local repo to the cloud |
| 97 | +git remote add origin https://github.com/your-username/my-first-repo.git |
| 98 | + |
| 99 | +# Rename your main branch to 'main' (standard practice) |
| 100 | +git branch -M main |
| 101 | + |
| 102 | +# Upload your code! |
| 103 | +git push -u origin main |
| 104 | +``` |
| 105 | + |
| 106 | +## How to Check Your Work |
| 107 | + |
| 108 | +Refresh your GitHub repository page. You should see your `hello.txt` file sitting there! |
| 109 | + |
| 110 | +```mermaid |
| 111 | +sequenceDiagram |
| 112 | + participant PC as Your Computer (Local) |
| 113 | + participant GH as GitHub (Cloud) |
| 114 | + |
| 115 | + PC->>PC: git init |
| 116 | + PC->>PC: git add & commit |
| 117 | + PC->>GH: git push |
| 118 | + GH-->>PC: Successfully uploaded! |
| 119 | +
|
| 120 | +``` |
| 121 | + |
| 122 | +## Common Commands Cheat Sheet |
| 123 | + |
| 124 | +| Command | Purpose | |
| 125 | +| --- | --- | |
| 126 | +| `git status` | See which files are modified or staged. | |
| 127 | +| `git log` | See the history of all your commits. | |
| 128 | +| `git diff` | See exactly what lines changed in your files. | |
| 129 | +| `git branch` | List your current branches. | |
| 130 | + |
| 131 | +:::success 🎉 Congratulations! |
| 132 | +You are now officially using Version Control. You have a local history on your computer and a backup in the cloud. You are ready to start building real backend applications! |
| 133 | +::: |
0 commit comments