【无标题】

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

相关推荐
一次旅行44 分钟前
act本地预跑GitHub Actions:Python项目完整CI/CD流水线实战
python·ci/cd·github
敢敢是只喵i1 小时前
Agent 为什么需要 guidance,但不能把 guidance 当成安全策略?
github·aigc
不简说1 小时前
JS 代码技巧 vol.9 — 20 个设计模式在真实项目里的应用
前端·javascript·github
最后冰吻free2 小时前
git 不新增commit修改中间commit对应的文件
git
芳草萋萋鹦鹉洲哦2 小时前
【git】重新生成并添加 SSH Key(Mac)
git·macos·ssh
逛逛GitHub2 小时前
很多神级开源 Agent 从它演化而来:77K Star 的 Pi 太强了。
github
午安~婉3 小时前
git中http与ssh连接
git·http·ssh
@Demi3 小时前
前端开发 Git 分支与 Tag 管理规范
大数据·git·elasticsearch
今夕资源网3 小时前
SayIt语音输入+AI 润色 Typeless 替代品 GitHub开源语音输入法,可本地部署LLM亦可接入deepseek 或者其他大模型。
人工智能·开源·github·输入法·开源输入法·语音输入法
chaors16 小时前
DeepResearchSystem 0x03:HITL
llm·github·ai编程