【Git】本地仓库关联远程仓库

Git 本地项目关联远程仓库

本地

本地已有项目

● 项目 07.GitLocalTest 包含有一个js

○ test.js

远程仓库

● 远程仓库地址

https://github.com/Sonnenlicht77/gitTest.git

○ 仓库只有一个 readme.md

关联

1.本地
1.1 本地仓库

git init

git add .

git commit -m "初始化本地仓库"

此时,只需将本地仓库和远程仓库连接起来即可。

1.2 连接 远程仓库

git remote add origin https://github.com/Sonnenlicht77/gitTest.git

git pull

○ 此时,会报:

bash 复制代码
warning: no common commits
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
From https://github.com/Sonnenlicht77/gitTest
 * [new branch]      main       -> origin/main
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.

    git pull <remote> <branch>

If you wish to set tracking information for this branch you can do so with:

    git branch --set-upstream-to=origin/<branch> master

git branch --set-upstream-to=origin/main : 根据提示,通过 设置分支绑定跟踪

bash 复制代码
Branch 'master' set up to track remote branch 'main' from 'origin'.

git pull : 显示

bash 复制代码
fatal: refusing to merge unrelated histories

git fetch origin main :

git merge --allow-unrelated-histories :

git push

bash 复制代码
Enumerating objects: 6, done.
Counting objects: 100% (6/6), done.
Delta compression using up to 4 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (5/5), 528 bytes | 176.00 KiB/s, done.
Total 5 (delta 0), reused 0 (delta 0)
To https://github.com/Sonnenlicht77/gitTest.git
   0c1b5c6..6fd9ac8  master -> main

最后,远程仓库有了 test.js ;本地仓库有了 readme.md 文档

相关推荐
计算机魔术师4 分钟前
终端用户
前端
码事漫谈28 分钟前
把 AI 拆掉,你的系统还能跑吗?
前端·后端
默_笙1 小时前
⛵ 我用 React + TS 做了个"调色盘",顺便学会了企业级项目的目录架构
前端·javascript
预知同行1 小时前
从 MCP 到 CLI:AI Agent 工具链的架构演进与实战抉择
前端·面试
何智超2 小时前
AI 微前端性能优化之旅(中):重启
前端·vibecoding
渣波2 小时前
拒绝 Redux 样板代码:Zustand 核心原理与实战进阶指南(基础、异步与切片模式)
前端·javascript
C++、Java和Python的菜鸟2 小时前
第12章 前端Web进阶(Vue工程化+ElementPlus)
前端·javascript·vue.js
Hamm2 小时前
前端转Java+AI全栈?那我推荐几个实战开源项目给你
前端·后端·全栈
饼干哥哥2 小时前
十年数据分析经验,被我打包成了4个跨境VOC Skill
前端·数据分析·数据可视化
东方小月2 小时前
从零开发一个 Coding Agent(六):实现一个可脚本化的 Faux Provider
前端·人工智能