Ir al contenido

Associating Repositories with Local Folders

Esta página aún no está disponible en tu idioma.

Associating Repositories with Local Folders

Section titled “Associating Repositories with Local Folders”

This section explains how to link a remote repository (on GitHub or Gitee) with a local project folder — the essential first step in using Git for version control. After completing this section, you will be able to:

  • Clone a remote repository to your local machine via the IDE
  • Initialize a local project, create a remote repository via CLI/API, and link them
  • Choose the right approach based on your project stage

Before starting this section, make sure you have:

  • Completed the Git Version Control Basics section
  • Installed Trae IDE or Qoder
  • A GitHub or Gitee account
  • Git credentials configured (see “Gitee Domestic Code Hosting Platform Guide”)

There are two common ways to associate a remote repository with a local folder. Choose the one that fits your project stage:

Method 1: Clone a Remote Repository via IDE (Best for Starting Fresh)

Section titled “Method 1: Clone a Remote Repository via IDE (Best for Starting Fresh)”

This is the most straightforward approach — the remote repository already exists, and you just need to pull it down locally.

Steps in Trae / Qoder:

  1. Open Trae (or Qoder) and click “New Window” (or use File → New Window)
  2. On the welcome page, find and click “Clone Repository”
  3. In the prompt, paste the repository URL:
    https://github.com/your-username/repo-name.git
    For Gitee, use:
    https://gitee.com/your-username/repo-name.git
  4. Choose a local directory (e.g., ~/Projects/) and confirm
  5. The IDE runs git clone automatically and opens the project folder

Tip: If you have SSH keys configured, you can paste the SSH URL instead:

git@github.com:your-username/repo-name.git

Once cloned, the local folder is automatically linked to the remote repository. All subsequent push and pull operations will sync automatically.

Section titled “Method 2: Create Local Project First, Then Link to Remote (Best for Existing Projects)”

If you already have a local project and want to push it to a remote hosting platform, follow these steps:

Step 1: Initialize a Local Git Repository

Terminal window
# Navigate to your project directory
cd ~/Projects/my-iot-project
# Initialize the Git repository
git init
# Stage all files and make an initial commit
git add .
git commit -m "Initial commit"

Step 2: Create a Remote Repository via CLI

You can create a remote repository without opening a browser by using the platform’s API.

For GitHub:

Terminal window
# Using the GitHub CLI (gh)
gh repo create my-iot-project --private --source=. --push
# Or using the GitHub API directly
curl -X POST https://api.github.com/user/repos \
-H "Authorization: token YOUR_GITHUB_TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
-d '{
"name": "my-iot-project",
"description": "My IoT project",
"private": true,
"auto_init": false
}'

For Gitee:

Terminal window
curl -X POST https://gitee.com/api/v5/user/repos \
-H "Content-Type: application/json" \
-d '{
"access_token": "YOUR_GITEE_TOKEN",
"name": "my-iot-project",
"description": "My IoT project",
"private": true,
"auto_init": false
}'

Tip: You can also ask your AI assistant to handle this. In Trae / Qoder’s Agent mode, simply say:

  • “Create a private repository named my-iot-project on GitHub”

The AI will call the appropriate CLI tool or API. If the tool isn’t installed, the AI will guide you through installation.

Step 3: Link Local Repository to Remote

Terminal window
# Add the remote origin
git remote add origin https://github.com/your-username/my-iot-project.git
# Push local code to the remote repository
git branch -M main
git push -u origin main

Your local project is now linked to the remote repository. You can use git push / git pull to sync code going forward.

Note: If you prefer SSH:

Terminal window
git remote add origin git@github.com:your-username/my-iot-project.git
AspectMethod 1: IDE CloneMethod 2: Local + CLI
Best forRemote repo exists, starting freshLocal code exists, need to upload
Entry pointIDE graphical interfaceTerminal / AI assistant
Browser needed?No (repo already created online)No (created via API)
Core commandsgit clonegit init + git remote add + git push

Regardless of which method you used, verify the link with these commands:

Terminal window
# Check the remote URL
git remote -v
# Expected output:
# origin https://github.com/your-username/my-iot-project.git (fetch)
# origin https://github.com/your-username/my-iot-project.git (push)
# Test fetching from remote
git fetch origin
# No errors means the association is working
SkillKey Operations
IDE cloneNew Window → Clone Repository → paste URL → choose path
CLI create remoteGitHub gh CLI or API curl call — no browser needed
Link local to remotegit remote add origin + git push -u origin main
Verify associationgit remote -v and git fetch origin

Building a commercial IoT product?

We provide ESP32 ODM design-to-manufacturing services. From prototype to production — the team behind this tutorial can build it with you.

Talk to us →