【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 文档

相关推荐
广州华水科技9 小时前
单北斗GNSS在变形监测中的优势与应用分析
前端
慕容引刀9 小时前
告别Commit信息纠结:使用Git AI Commit插件实现规范化提交
人工智能·git·github·visual studio code·visual studio
程序员爱钓鱼10 小时前
Rust 变量与不可变性:为什么默认不能修改变量?
前端·后端·rust
随风一样自由10 小时前
【前端工程化】前端工程化解耦实践:从问题分析到架构重构
前端·重构·架构
vortex510 小时前
Web 渗透测试:未授权与越权漏洞全流程挖掘思路
前端
我有满天星辰11 小时前
【前端模块化】前端模块化演进之路:从脚本堆砌到标准统一
前端
我有满天星辰11 小时前
Vue 3 响应式双雄:ref 与 reactive 完全指南
前端·javascript·vue.js
随风一样自由19 小时前
【前端独角兽】刚进入前端领域的前端开发用jQuery还是Vue3?
前端·javascript·vue3·jquery
IMPYLH20 小时前
HTML 的 <data> 元素
前端·html
YHHLAI20 小时前
[特殊字符] 面试中的 Promise —— 从入门到精通
前端·javascript·面试