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
相关推荐
殷紫川14 分钟前
IDEA 集成 GitHub Copilot 指南:解锁 10 倍编码效率的全链路实战
github·intellij idea·github copilot
八号老王3 小时前
Google Cloud Vertex AI 接入 OpenClaw 记录
github
子兮曰4 小时前
同样做中文平台自动化:为什么你越跑越贵,而 OpenCLI 越跑越稳
前端·github·命令行
CoderJia程序员甲4 小时前
GitHub 热榜项目 - 日榜(2026-04-01)
人工智能·ai·大模型·github·ai教程
我先去打把游戏先4 小时前
Git 一个本地仓库同时推送到两个远程仓库(私人 GitHub + 公司 Git)保姆级教程
git·vscode·单片机·嵌入式硬件·物联网·学习·github
汪海游龙4 小时前
04.02 AI 精选:终端里的 AI 编程代理工具
github
看海的四叔5 小时前
【Linux】命令行常规操作全攻略:入门+实战+速查
linux·运维·github·命令行·batch命令
今夕资源网6 小时前
github开源桌面快速启动神器:ZTools 高性能 可扩展应用启动器,支持macOS/Windows,适配办公与开发需求
macos·github·工具箱·ztools·桌面启动·音速启动·高性能启动器
evan202017 小时前
Qwen3-ASR 1.7B 音频转字幕 懒人整合包
github
CoovallyAIHub20 小时前
VisionClaw:智能眼镜 + Gemini + Agent,看一眼就能帮你搜、帮你发、帮你做
算法·架构·github