github使用教程

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

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改名

git branch -M main 

2、查看有哪些分支

git branch -a 

3、删除远程分支

git push origin --delete master

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

git checkout main 

5、合并分支

git merge remotes/origin/main

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

git merge remotes/origin/main --allow-unrelated-histories 

6、提交修改

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

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

洲洲不是州州

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值