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”Overview
Section titled “Overview”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
Prerequisites
Section titled “Prerequisites”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”)
Two Approaches
Section titled “Two Approaches”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:
- Open Trae (or Qoder) and click “New Window” (or use
File → New Window) - On the welcome page, find and click “Clone Repository”
- In the prompt, paste the repository URL:
For Gitee, use:https://github.com/your-username/repo-name.githttps://gitee.com/your-username/repo-name.git
- Choose a local directory (e.g.,
~/Projects/) and confirm - The IDE runs
git cloneautomatically 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.
Method 2: Create Local Project First, Then Link to Remote (Best for Existing Projects)
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
# Navigate to your project directorycd ~/Projects/my-iot-project
# Initialize the Git repositorygit init
# Stage all files and make an initial commitgit 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:
# Using the GitHub CLI (gh)gh repo create my-iot-project --private --source=. --push
# Or using the GitHub API directlycurl -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:
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
# Add the remote origingit remote add origin https://github.com/your-username/my-iot-project.git
# Push local code to the remote repositorygit branch -M maingit push -u origin mainYour 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
Comparison
Section titled “Comparison”| Aspect | Method 1: IDE Clone | Method 2: Local + CLI |
|---|---|---|
| Best for | Remote repo exists, starting fresh | Local code exists, need to upload |
| Entry point | IDE graphical interface | Terminal / AI assistant |
| Browser needed? | No (repo already created online) | No (created via API) |
| Core commands | git clone | git init + git remote add + git push |
Verifying the Association
Section titled “Verifying the Association”Regardless of which method you used, verify the link with these commands:
# Check the remote URLgit 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 remotegit fetch origin# No errors means the association is workingSummary
Section titled “Summary”| Skill | Key Operations |
|---|---|
| IDE clone | New Window → Clone Repository → paste URL → choose path |
| CLI create remote | GitHub gh CLI or API curl call — no browser needed |
| Link local to remote | git remote add origin + git push -u origin main |
| Verify association | git remote -v and git fetch origin |
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 →