【无标题】

创建本地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

相关推荐
cen__y8 小时前
Linux12(Git01)
linux·运维·服务器·c语言·开发语言·git
海蓝可知天湛9 小时前
Agent&IELTS雅思口语专属语料库
人工智能·github·rag·ielts·skills
ServBay10 小时前
OpenCode 和它的7款必备插件
后端·github·ai编程
Yunzenn11 小时前
字节最新研究cola-DLM第 01 章:语言生成的三次范式之争 —— 从 RNN 到 AR 到扩散
架构·github
wangruofeng11 小时前
GitHub AI 月榜解读:8 大趋势告诉你该关注什么
github·ai编程
bukeyiwanshui11 小时前
20260518 Swift实验
git·swift
qziovv11 小时前
Git 回退场景
大数据·git·elasticsearch
小小测试开发14 小时前
AI 水印攻防战:OpenAI 引入 SynthID 认证,GitHub 同步出现去水印工具
人工智能·github
来自大山深处的Doge_14 小时前
解决Git提交更新更改时出错: detected dubious ownership in repository at ...
git
微软技术栈15 小时前
Microsoft AI Genius 4.0 | 使用 GitHub Copilot SDK 升级开发者体验
人工智能·microsoft·github