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

相关推荐
HHHHHY8 分钟前
http接口响应头类型不对,导致svg图片无法预览,前端解决方案
前端·javascript
洛小豆11 分钟前
Git打标签仓库看不到?她说:豆子,你又忘了加 --tags!
git·后端·github
Komorebi゛17 分钟前
【React】配置别名路径
前端·react.js·前端框架
风语者日志20 分钟前
CTFSHOW WEB 3
前端
普通码农40 分钟前
uni.setClipboardData在 iOS 剪贴板复制失败解决方案
前端
_孤傲_42 分钟前
webpack实现常用plugin
前端·webpack·node.js
golang学习记1 小时前
从0死磕全栈之Next.js 字体优化实战:零布局偏移、高性能、隐私友好的字体加载方案
前端
zachhere1 小时前
深入了解 OpenAI Apps SDK 的内部机制
前端
张可爱1 小时前
20251015-Vue3八股文整理
前端