Git操作GitHub全记录

仅供本人记录查阅

全网最丝滑的 本地仓库上传GitHub操作 (Git建立本地仓库并上传代码到GitHub中)-------摆脱繁琐和冗余 清晰明了!!

全网最丝滑的 Git克隆远程仓库操作 (Git克隆远程仓库并上传代码到远程仓库中)-------摆脱繁琐和冗余 清晰明了!!

Git 删除 GitHub仓库的文件——详细操作

一. GitHub ssh-key配置

  1. 验证
ssh -T git.com
  1. 配置用户名和邮箱
git config --global user.name "EliasJie"
git config --global user.email "meiyouyudi@qq.com"
  1. 生成ssh-key
ssh-keygen -t rsa -C "meiyouyudi@qq.com"

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

93254 MINGW64 ~/Desktop
$ ssh-keygen -t rsa -C "meiyouyudi@qq.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/93254/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/93254/.ssh/id_rsa
Your public key has been saved in /c/Users/93254/.ssh/id_rsa.pub
The key fingerprint is:
SHA256:7jECk2ix0lWMXzSEDFG4J8jzfBLBzmn5jDVNijzpDQk meiyouyudi.com
The key's randomart image is:
+---[RSA 3072]----+
|     o.. o*+.    |
|    ..E B  o.    |
|  . .o O X +     |
| . = .= ^ = .    |
|. = +  *S% .     |
| o   o .* =      |
|      . +o       |
|       o o       |
|        .        |
+----[SHA256]-----+

93254 MINGW64 ~/Desktop
$ ssh -T git.com
The authenticity of host 'github.com (20.405.243.196)' can't be established.
ED25519 key fingerprint is SHA456:+DiY3wvvVfduJJhbpZisF/zLDA0zPMSvHdkr4UvCOqU.
This key is not known by any other names.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'github.com' (ED25519) to the list of known hosts.
Hi EliasJie! You've successfully authenticated, but GitHub does not provide shell access.

93254 MINGW64 ~/Desktop
$

二. 添加GitHub仓库

在这里插入图片描述
在这里插入图片描述

Git提交本地代码到Github仓库

远程克隆仓库到本地的文件夹再上传

本人以前写的
四. 克隆远程仓库 (核心操作)
现在写的

在这里插入图片描述

  • 显示当前Github仓库的状态
git status
93254@WIN11DC MINGW64 ~/Desktop/OpenMV_Software (main)
$ git status
On branch main
Your branch is up to date with 'origin/main'.

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        OpenMV peripheral/
        Project/
        ei_object_detection.py
        labels.txt

nothing added to commit but untracked files present (use "git add" to track)

  • 输入git add .
git add .
  • 输入 git commit -m 'first commits'第一次会让输入git的邮箱、用户名,输入一下
git commit -m 'First commits'
  • 输入git push将本地仓库中的提交(commits)推送到远程仓库
93254@WIN11DC MINGW64 ~/Desktop/OpenMV_Software (main)
$ git push
Enumerating objects: 65, done.
Counting objects: 100% (65/65), done.
Delta compression using up to 20 threads
Compressing objects: 100% (54/54), done.
Writing objects: 100% (64/64), 130.36 KiB | 379.00 KiB/s, done.
Total 64 (delta 2), reused 2 (delta 0), pack-reused 0 (from 0)
remote: Resolving deltas: 100% (2/2), done.
To github.com:EliasJie/OpenMV_Software.git
   3ebb816..004f36f  main -> main


问题:如出现 error: failed to push some refs to

To github.com:EliasJie/Share-library.git
 ! [rejected]        main -> main (fetch first)
error: failed to push some refs to 'github.com:EliasJie/Share-library.git'
hint: Updates were rejected because the remote contains work that you do not
hint: have locally. This is usually caused by another repository pushing to
hint: the same ref. If you want to integrate the remote changes, use
hint: 'git pull' before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

在这里插入图片描述
解决:先git pull,后git push

git pull
git push

93254@WIN11DC MINGW64 ~/Desktop/Share-library (main) $ git pull
remote: Enumerating objects: 5, done. remote: Counting objects: 100%
(5/5), done. remote: Compressing objects: 100% (2/2), done. remote:
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 Unpacking
objects: 100% (3/3), 978 bytes | 81.00 KiB/s, done. From
github.com:EliasJie/Share-library 9da07f1…e3e8276 main ->
origin/main Merge made by the ‘ort’ strategy. README.md | 4 ++± 1
file changed, 3 insertions(+), 1 deletion(-)

93254@WIN11DC MINGW64 ~/Desktop/Share-library (main) $ git push
Enumerating objects: 19, done. Counting objects: 100% (15/15), done.
Delta compression using up to 20 threads Compressing objects: 100%
(9/9), done. Writing objects: 100% (9/9), 451.71 KiB | 1.29 MiB/s,
done. Total 9 (delta 2), reused 0 (delta 0), pack-reused 0 (from 0)
remote: Resolving deltas: 100% (2/2), completed with 2 local objects.
To github.com:EliasJie/Share-library.git e3e8276…e5746f1 main -> main

本地的无.git的文件夹上传到远程仓库

本人以前写的

第五、七节上传文件代码到远程仓库(重点操作 详细步骤)

三. Git删除Github仓库或某个文件或文件夹

1.删除已有Github仓库

删除Github中没有用的仓库

进入到需要删除的仓库里面,找到“settings”即仓库设置,

然后,在仓库设置里拉到最底部,找到“Danger Zone”即危险区域,

点击“Delete this repository”这样就可以删除该仓库了。

在这里插入图片描述

2.删除Github中的某个文件或文件夹

我们知道,在Github上我们只能删除仓库,并不能删除文件或者文件夹,所以只能用命令来解决。

①如果没有建立本地库或者克隆远程库,需

  • 新建文件夹

  • git bash here
    在新建的文件夹里右键git bash here打开终端,并执行git init初始化仓库

  • git clone <你的地址>
    找到github上要删除的仓库地址,并复制,在终端里输入git clone <你的地址>

②如果已经有建立本地库或者克隆远程库,需

  • 要删除文件的库里右键git bash here打开终端

在这里插入图片描述

在这里插入图片描述

  • 假如要删除GitHub的Project2此文件夹

  • 在终端里输入dir查看此文件夹下的文件和目录(文件夹)

在这里插入图片描述

  • 删除本地仓库文件 git rm ,filename是你要删除的文件名字
git rm <filename>
  • 文件夹的删除和文件不一样,需要多一个参数,如下
    删除本地仓库文件夹 git rm -r,filename是你要删除的文件夹名字
git rm -r <filename>

我们要删除GitHub的Project2此文件夹

在这里插入图片描述

  • 将本地内容推送到远程仓库 git push
git commit -m "XXXX"

在这里插入图片描述

  • 把删除的文件恢复到最新版本 git checkout
git checkout
  • 将本地内容推送到远程仓库 git push
git push

在这里插入图片描述

删除总流程

在这里插入图片描述

刷新github仓库 就看见选定删除的文件夹没有了!!!大功告成!

在这里插入图片描述

四. Git 错误记录


Another git process seems to be running in this repository, e.g.
an editor opened by ‘git commit’. Please make sure all processes
are terminated then try again. If it still fails, a git process
may have crashed in this repository earlier:
remove the file manually to continue.解决


  1. 错误
    error: remote origin already exists.
git remote -v
git remote rm origin

在这里插入图片描述

在这里插入图片描述


  1. 我这里出现错误
    fatal: unable to access ‘https://github.com/Noroom569/text.git/’: OpenSSL SSL_read: Connection was reset, errno 10054
    在这里插入图片描述
git config --global http.sslVerify "false"

在这里插入图片描述


  1. 问题:如出现
    error: failed to push some refs to ‘github.com:EliasJie/detectron2_tower.git’
    hint: Updates were rejected because the remote contains work that you do not
    hint: have locally. This is usually caused by another repository pushing to
    hint: the same ref. If you want to integrate the remote changes, use
    hint: ‘git pull’ before pushing again.
    hint: See the ‘Note about fast-forwards’ in ‘git push --help’ for details.

在这里插入图片描述

这个错误再次出现是因为你的本地main分支仍然是非快速前进的推送(non-fast-forward),也就是说远程仓库的main分支有新的提交,而你的本地分支没有这些提交。你需要先拉取远程的更新,然后再尝试推送。你可以按照以下步骤操作:

拉取远程更新: 使用git pull命令将远程仓库的最新变更合并到你的本地main分支:

解决:先git pull,后git push

git pull origin main

git push

在这里插入图片描述


在这里插入图片描述
在这里插入图片描述

  1. 问题:如出现
    fatal: ‘main’ does not appear to be a git repository
    fatal: Could not read from remote repository.
    Please make sure you have the correct access rights
    and the repository exists.

在这里插入图片描述
解决:

git remote -v
git remote rm origin
git remote add origin git@github.com:xxx.git

在这里插入图片描述

以后有问题继续扩充:

在这里插入图片描述

  • 20
    点赞
  • 26
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

没有余地 EliasJie

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

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

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

打赏作者

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

抵扣说明:

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

余额充值