【无标题】

创建本地Git仓库并推送到远程仓库

  • [1 创建远程仓库](#1 创建远程仓库)
  • [2 创建本地仓库](#2 创建本地仓库)
  • [3 关联本地仓库与远程仓库](#3 关联本地仓库与远程仓库)
  • [4 从远程仓库拉取代码](#4 从远程仓库拉取代码)
    • [4.1 Merge](#4.1 Merge)
    • [4.2 Rebase](#4.2 Rebase)
  • [5 提交本地代码到远程仓库](#5 提交本地代码到远程仓库)

1 创建远程仓库

例如在Gitee上:https://gitee.com/xxx/yyy.git

2 创建本地仓库

在本地源码的根目录下运行如下命令,例如:c:\yyy

git init

git add .

git status

git commit -m "The first commit to remote repo"

git status

3 关联本地仓库与远程仓库

git remote add origin https://gitee.com/xxx/yyy.git

4 从远程仓库拉取代码

git pull origin master

可能会报错:

复制代码
$ git pull origin master
remote: Enumerating objects: 5, done.
remote: Counting objects: 100% (5/5), done.
remote: Compressing objects: 100% (5/5), done.
remote: Total 5 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (5/5), 2.84 KiB | 104.00 KiB/s, done.
From https://gitee.com/qp1886358/kafka-springboot
 * branch            master     -> FETCH_HEAD
 * [new branch]      master     -> origin/master
fatal: refusing to merge unrelated histories

有两种选择解决以上问题:

4.1 Merge

运行命令:

git pull origin master --allow-unrelated-histories

如果有冲突,需要手动解决冲突,然后运行命令:

git add <conflicted_files>

git commit -m "Solved all the conflicts"

4.2 Rebase

git pull --rebase origin master

如果有冲突,需要手动解决冲突,然后运行命令:

git add <conflicted_files>

git rebase --continue

如果要退出rebase,可以运行命令:

git rebase --abort

5 提交本地代码到远程仓库

运行命令:

git push --set-upstream origin master

git push -u origin master

相关推荐
徐小夕1 小时前
jitword 协同文档3.2发布:打造浏览器中最强word编辑器
前端·架构·github
齐翊3 小时前
分享一个在 Claude Code 里 [同时] 用多个 ApiKey 的方法
程序员·github·agent
A_Lonely_Cat3 小时前
记一次 GitHub 幽灵协作者大清洗:强制重写 Git 历史与穿透 CDN 缓存实践
git·github
极光技术熊20 小时前
Spring AI 从入门到精通:构建你的 AI 开发知识体系
后端·github
用户394839510755321 小时前
怎么让我的 Agent 真正"懂"我?——关于记忆、经验学习与预测的一些真实体验
github
远航_1 天前
git submodule
前端·后端·github
fthux1 天前
如果你用 Mac,那你可能需要 Noti Shift
macos·开源·github
程序员天天困2 天前
Loop Engineering 实战:/goal 命令让 AI 自己写完整项目
github
徐小夕2 天前
我们开源了一款“框架无关”的思维导图编辑器,3分钟集成到任意系统
前端·javascript·github
小爷毛毛_卓寿杰2 天前
我把 397B 的「Agentic 大脑」塞进了 Xinference,一键部署 Nex-N2
人工智能·架构·github