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

相关推荐
object not found29 分钟前
WooCommerce 接入 KPay 后订单完成页不显示订单信息:returnUrl 动态参数问题解决
前端·wordpress·独立站支付
yume_sibai40 分钟前
04-Nginx部署实战完全指南(前端部署 + 后端代理 + 监控告警 + 故障排查)
运维·前端·nginx
data analyse 4561 小时前
数据合规的同意记录怎么留存?
前端·人工智能·数据分析
linux_cfan1 小时前
videojs v10 源代码系列解读:35 · HLS 解析器:multivariant 与 media playlist
前端·javascript·音视频
IT_陈寒1 小时前
Redis键过期失效?这个坑我踩得明明白白
前端·人工智能·后端
web打印社区1 小时前
汽修 / 4S 店:维修工单、结算单网页怎么静默出纸
开发语言·前端·javascript·chrome·ecmascript
行者-全栈开发1 小时前
【码动四季·秋】从 commit 到发版全自动:Conventional Commits + semantic-release 发布流水线实战
git·ci/cd·自动化发布·atomgit·semantic-releas·语义化版本自动化·git 提交规范落地
liangshanbo12151 小时前
Webpack的分包策略面试题
前端·webpack·node.js
ttwuai1 小时前
Golang Web后台管理框架推荐:Gin、GoFrame与数据面板项目怎么分
前端·golang·gin