github使用教程

一、常用命令有以下几个:

bash 复制代码
git init
git config --global user.email"邮箱" 
git config --global user.name"Aurorajwj" 
git add . 
git commit -m "first commit"
git remote add origin https://github.com/XXX.git
git push -u origin master

//上传时仓库非空时改用
git push origin master     

二、master 和main 分支问题

1、先给本地分支master改名

bash 复制代码
git branch -M main 

2、查看有哪些分支

bash 复制代码
git branch -a 

3、删除远程分支

bash 复制代码
git push origin --delete master

4、切换到当前分支main,也就要保留下来的分支

bash 复制代码
git checkout main 

5、合并分支

bash 复制代码
git merge remotes/origin/main

如果显示拒绝合并,则使用

bash 复制代码
git merge remotes/origin/main --allow-unrelated-histories 

6、提交修改

bash 复制代码
git push origin main

三、使用 https 的方式拉取或者推送代码,每次都需要手动输入用户名和 personal access token,比较麻烦,为了方便 使用 windows 中的凭据管理器保存相关配置

四、遇到的问题

1、问题描述:

我对原本已经上传到远程仓库的项目进行了更新,然后想把更新的部分再次使用push命令提交更新时发现报错。

复制代码
error: failed to push some refs to 'https://github.com/li-zhouzhou/DRV8313_project.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

更新前应该先pull一下,运行一下命令:

复制代码
git pull --rebase origin master

该命令的意思是把远程库中的更新合并到(pull=fetch+merge)本地库中,---rebase的作用是取消掉本地库中刚刚的commit,并把他们接到更新后的版本库之中

然后在运行命令:

复制代码
git push origin master
相关推荐
油泼辣子多加6 小时前
2025年06月30日Github流行趋势
github
ai小鬼头7 小时前
AIStarter如何快速部署Stable Diffusion?**新手也能轻松上手的AI绘图
前端·后端·github
寻月隐君11 小时前
Rust 异步编程实践:从 Tokio 基础到阻塞任务处理模式
后端·rust·github
bingGO5499111 小时前
github 集成CICD自动化部署
github
超龄超能程序猿12 小时前
Bitvisse SSH Client 安装配置文档
运维·ssh·github
Natsume171015 小时前
嵌入式开发:GPIO、UART、SPI、I2C 驱动开发详解与实战案例
c语言·驱动开发·stm32·嵌入式硬件·mcu·架构·github
荔枝吻16 小时前
【AI总结】Git vs GitHub vs GitLab:深度解析三者联系与核心区别
人工智能·git·github
幻凡ss16 小时前
github pages使用免费CDN加速-netlify
github·github pages·github cdn·github pages加速·netlify加速github·hexo博客免费cdn加速·个人博客免费cdn加速
我是哪吒18 小时前
分布式微服务系统架构第155集:JavaPlus技术文档平台日更-Java线程池实现原理
后端·面试·github
DeepSeek-大模型系统教程1 天前
推荐 7 个本周 yyds 的 GitHub 项目。
人工智能·ai·语言模型·大模型·github·ai大模型·大模型学习