Git使用指北


前言:注意!使用git时,开始工作前先pull,结束工作后要push!!!
前言:注意!使用git时,开始工作前先pull,结束工作后要push!!!
前言:注意!使用git时,开始工作前先pull,结束工作后要push!!!

先选中文件夹,右键,选择 Git Bash Here

第一次链接上传

新建仓库

git init
git config --global user.name "名字"
git config --global user.email "邮箱"

准备提交

// 单文件提交:git add 文件名
// 全部文件提交:git add .
git add .
git commit -m "提交信息"

链接仓库

法一:使用HTTPS连接

git remote add origin https://github.com/仓库.git

法二:使用SSH连接

git remote set-url origin git@github.com:仓库.git

如果 HTTPS 连接不稳定,考虑切换到 SSH 方式来进行推送

上传仓库

// 注意远程仓库新建时不要手动添加readme文件
git push -u origin main

后续上传

准备提交

// 单文件提交:git add 文件名
// 全部文件提交:git add .
git add .
git commit -m "提交信息"

上传仓库

git push origin main

修改commit

git commit --amend

一些常用命令

查看日志

git log

退出按q

下拉代码

git pull

查看分支状态

git status

良好的分支习惯:

  1. 每次提交到一个新的本地分支
git checkout -b newbranch
<修改代码>
  1. 获取远程分支
git add .
git commit -m "提交信息"
  1. 将拉取到的远程分支与之前提交的本地分支合并
git checkout main
git pull
git merge newbranch
  1. 提交
git push

Github上传代码及解决main主分支问题

https://blog.youkuaiyun.com/Arcofcosmos/article/details/112862038

git 分支命名规范

https://blog.youkuaiyun.com/a6864657/article/details/107236221

参考:
https://www.runoob.com/git/git-remote-repo.html
https://blog.youkuaiyun.com/BUCTOJ/article/details/89879619

一些报错

* branch            main       -> FETCH_HEAD
fatal: refusing to merge unrelated histories

原因:
本地仓库与远程仓库的历史记录不相关,通常是因为你在本地初始化了一个新仓库,而远程仓库已经有了一些提交
解决方法:

  1. 拉取远程更改并允许不相关历史合并:
git pull origin main --allow-unrelated-histories
  1. 推送本地更改
git push origin main

注意:使用--allow-unrelated-histories选项时,请确保你确实想合并这两个不同历史的仓库,特别是在团队协作的情况下,以免丢失重要的提交记录。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值