【无标题】

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

相关推荐
Cosmoshhhyyy5 小时前
mac环境下安装git并配置密钥等
git·macos
yuwei0215 小时前
git大全解
git
超级小忍6 小时前
深入解析 GitHub Actions 工作流文件编写:从入门到实战
github
Haku Coder7 小时前
我的第一个音乐元素浏览项目上传至Github啦!
github
程序媛Dev9 小时前
还在 SSH 连服务器敲 SQL?我用 Sealos 把数据库管理后台搬进了浏览器!
开源·github
小林的技术分享10 小时前
版本控制系统-Git 学习 《progit》电子书学习记录 第一章 (仅隔个人学习记录用)
git
weixin_4569042711 小时前
Git登录配置的详细方法
git
猫头虎11 小时前
猫头虎AI分享|一款Coze、Dify类开源AI应用超级智能体Agent快速构建工具:FastbuildAI
人工智能·开源·github·aigc·ai编程·ai写作·ai-native
Onion_9912 小时前
学习下Github上的Android CICD吧
android·github
鄃鳕15 小时前
Git , 本地落后远端
git