[github全教程]github版本控制最全教学------- 大厂找工作面试必备!

  • 作者:20岁爱吃必胜客(坤制作人),近十年开发经验, 跨域学习者,目前于新西兰奥克兰大学攻读IT硕士学位
  • 荣誉:阿里云博客专家认证、腾讯开发者社区优质创作者,在CTF省赛校赛多次取得好成绩。
  • 跨领域学习,喜欢摄影、弹吉他、咏春拳。文章深入浅出、语言风趣;爱吃必胜客社区创立者,旨在“发现美 欣赏美

  • 🏆 学习系列专栏
    。🏅 Python学习宝库
    。🏅 网络安全学习宝库

在这里插入图片描述

在这里插入图片描述

文章目录

  • ⭐️专业名词
    • 🌟 常用命令
    • 🌟 实践
  • ⭐️ssh- 证明你的身份github拥有者
    • 🌟 这个origin什么意思
      • ☀️git push -u origin master
      • ☀️一般流程
    • 🌟 分枝控制
      • ☀️main branch和 feature branch
  • ⭐️总结
    • 🌟

⭐️专业名词

在这里插入图片描述

🌟 常用命令

clone 下载项目
add 跟踪你的改变
commit 存到git上面
push 把本地git上传到远端-例如github, getlab, bitbucket
pull 把远端改变同步到本地

🌟 实践

zsh compinit: insecure directories, run compaudit for list.
Ignore insecure directories and continue [y] or abort compinit [n]? y~/Code/gitlea  on main +4 !4 ?6 ---------------------------------- at 17:13:04 
> ~/Code/gitlea  on main +4 !4 ?6 ---------------------------------- at 17:13:04 
> git clone git@github.com:KrisQK/demo-repo.git
正克隆到 'demo-repo'...
Enter passphrase for key '/Users/liqikun/.ssh/id_rsa': 
remote: Enumerating objects: 6, done.
remote: Counting objects: 100% (6/6), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 6 (delta 0), reused 0 (delta 0), pack-reused 0
接收对象中: 100% (6/6), 完成.~/Code/gitlea  on main +4 !4 ?7 ------------------------ took 36s  at 17:14:27 
> cd demo-repo ~/Code/gitlea/demo-repo  on main --------------------------------- at 17:14:53 
> ls -la
total 8
drwxr-xr-x@  4 liqikun  staff  128 12  1 17:14 .
drwxr-xr-x   3 liqikun  staff   96 12  1 17:13 ..
drwxr-xr-x@ 12 liqikun  staff  384 12  1 17:14 .git
-rw-r--r--@  1 liqikun  staff   31 12  1 17:14 README.md~/Code/gitlea/demo-repo  on main --------------------------------- at 17:16:11 
> git status
位于分支 main
您的分支与上游分支 'origin/main' 一致。无文件要提交,干净的工作区~/Code/gitlea/demo-repo  on main --------------------------------- at 17:17:14 
> git status
位于分支 main
您的分支与上游分支 'origin/main' 一致。尚未暂存以备提交的变更:(使用 "git add <文件>..." 更新要提交的内容)(使用 "git restore <文件>..." 丢弃工作区的改动)修改:     README.md修改尚未加入提交(使用 "git add" 和/或 "git commit -a")~/Code/gitlea/demo-repo  on main !1 ------------------------------ at 17:18:05 
> git status
位于分支 main
您的分支与上游分支 'origin/main' 一致。尚未暂存以备提交的变更:(使用 "git add <文件>..." 更新要提交的内容)(使用 "git restore <文件>..." 丢弃工作区的改动)修改:     README.md未跟踪的文件:(使用 "git add <文件>..." 以包含要提交的内容)index.html修改尚未加入提交(使用 "git add" 和/或 "git commit -a")~/Code/gitlea/demo-repo  on main !1 ?1 --------------------------- at 17:23:11 
> git add .         ~/Code/gitlea/demo-repo  on main +2 ------------------------------ at 17:24:09 
> git status
位于分支 main
您的分支与上游分支 'origin/main' 一致。要提交的变更:(使用 "git restore --staged <文件>..." 以取消暂存)修改:     README.md新文件:   index.html~/Code/gitlea/demo-repo  on main +2 ------------------------------ at 17:24:13 
> 

⭐️ssh- 证明你的身份github拥有者

ssh-keygen -t rsa -b 4096 -C "q---@--.com"

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

🌟 这个origin什么意思

origin 是 Git 中默认使用的远程仓库的默认名称。它实际上是远程仓库的一个别名,用于简化对远程仓库的引用和操作

当你克隆一个远程仓库时(例如通过 git clone 命令),Git 会自动为这个远程仓库添加一个默认的别名叫做 origin。这样,你就可以使用 origin 作为对远程仓库的引用,而不必每次都输入完整的远程仓库 URL。

例如,当你执行 git push origin main 时,origin 代表着远程仓库的地址(如 github.com:KrisQK/demo-repo.git),让 Git 知道你想要将本地的 main 分支推送到 origin 所指向的远程仓库。

你也可以根据需要为其他远程仓库设置不同的别名,但通常情况下,origin 是默认使用的远程仓库别名,它指向最初克隆的远程仓库。

☀️git push -u origin master

这个命令通常用于将本地的 master 分支推送到名为 origin 的远程仓库。-u 参数将本地的 master 分支与远程的 origin/master 分支关联起来,并设置本地 master 分支在以后的推送中默认使用 origin master 作为默认远程分支

然而,在你之前提供的错误信息中,似乎出现了一个与 SSH 密钥相关的问题,导致 Git 无法进行远程推送。这个错误可能与权限问题有关,可能是因为 Git 无法找到或使用正确的 SSH 密钥来访问远程仓库。

在处理 SSH 密钥问题之前,推送到远程仓库可能会失败。确保你的 SSH 密钥正确设置并且可以被 Git 使用,然后再次尝试推送到远程仓库。

☀️一般流程

在这里插入图片描述

🌟 分枝控制

☀️main branch和 feature branch

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

⭐️总结

在这里插入图片描述

~/Code/gitlea ----------------------------------- at 21:15:37 
> git remote add origin git@github.com:KrisQK/demo-repo2.git~/Code/gitlea ----------------------------------- at 21:33:18 
> git remote -v
origin  git@github.com:KrisQK/demo-repo2.git (fetch)
origin  git@github.com:KrisQK/demo-repo2.git (push)~/Code/gitlea ----------------------------------- at 21:33:30 
> cd demo-repo2     ~/Code/gitlea/demo-repo2  on master ------------- at 21:34:00 
> git remote -v~/Code/gitlea/demo-repo2  on master ------------- at 21:34:06 
> git remote add origin git@github.com:KrisQK/demo-repo2.git~/Code/gitlea/demo-repo2  on master ------------- at 21:34:12 
> git remote -v                                             
origin  git@github.com:KrisQK/demo-repo2.git (fetch)
origin  git@github.com:KrisQK/demo-repo2.git (push)~/Code/gitlea/demo-repo2  on master ------------- at 21:34:15 
> git push origin master
no such identity: /Users/liqikun/.ssh/id_ed25519: No such file or directory
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.Please make sure you have the correct access rights
and the repository exists.~/Code/gitlea/demo-repo2  on master ---- took 3s  at 21:34:41 
> git push -u origin master
no such identity: /Users/liqikun/.ssh/id_ed25519: No such file or directory
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.Please make sure you have the correct access rights
and the repository exists.~/Code/gitlea/demo-repo2  on master ---- took 3s  at 21:35:51 
> ssh-add ~/.ssh/qikunlikey
Identity added: /Users/liqikun/.ssh/qikunlikey (qikunli8866@gmail.com)~/Code/gitlea/demo-repo2  on master ------------- at 21:47:33 
> ssh-add -l
4096 SHA256:dSBFeXTx5B0kYbqEpyddMfSrpMCDBhUHGMWkqfklKZE qikunli8866@gmail.com (RSA)~/Code/gitlea/demo-repo2  on master ------------- at 21:48:10 
> git push -u origin master
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Writing objects: 100% (3/3), 233 bytes | 233.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
To github.com:KrisQK/demo-repo2.git* [new branch]      master -> master
branch 'master' set up to track 'origin/master'.~/Code/gitlea/demo-repo2  on master ---- took 5s  at 21:51:26 
> cd ..~/Code/gitlea ----------------------------------- at 00:00:42 
> cd demo-repo~/Code/gitlea/demo-repo  on main ---------------- at 00:00:54 
> ls
README.md  index.html~/Code/gitlea/demo-repo  on main ---------------- at 00:00:56 
> git branch~/Code/gitlea/demo-repo  on main ------- took 7s  at 00:01:28 
> git checkout -b feature-readme-instructions
Switched to a new branch 'feature-readme-instructions'~/C/g/demo-repo  on feature-readme-instructions - at 00:02:43 
> git branch~/C/g/demo-repo  on feature-readme-instructions 
> git checkout main                        
Switched to branch 'main'
Your branch is up to date with 'origin/main'.~/Code/gitlea/demo-repo  on main ---------------- at 00:03:34 
> git checkout feature-readme-instructions 
Switched to branch 'feature-readme-instructions'~/C/g/demo-repo  on feature-readme-instructions - at 00:03:54 
>                                          ~/C/g/demo-repo  on feature-readme-instructions - at 00:04:31 
> git status
On branch feature-readme-instructions
Changes not staged for commit:(use "git add <file>..." to update what will be committed)(use "git restore <file>..." to discard changes in working directory)modified:   README.mdno changes added to commit (use "git add" and/or "git commit -a")~/C/g/demo-repo  on feature-readme-instructions !1 
> git add .~/C/g/demo-repo  on feature-readme-instructions +1 
> git commit -m "updated readme"
[feature-readme-instructions e1737de] updated readme1 file changed, 4 insertions(+)~/C/g/demo-repo  on feature-readme-instructions - at 00:07:20 
> git checkout master
error: pathspec 'master' did not match any file(s) known to git~/C/g/demo-repo  on feature-readme-instructions - at 00:07:50 
> git checkout main  
Switched to branch 'main'
Your branch is up to date with 'origin/main'.~/Code/gitlea/demo-repo  on main ---------------- at 00:07:56 
> git diff feature-readme-instructions ~/Code/gitlea/demo-repo  on main ------ took 22s  at 00:09:19 
> git checkout feature-readme-instructions 
Switched to branch 'feature-readme-instructions'~/C/g/demo-repo  on feature-readme-instructions - at 00:10:14 
> git status
On branch feature-readme-instructions
nothing to commit, working tree clean~/C/g/demo-repo  on feature-readme-instructions - at 00:10:20 
> git push
fatal: The current branch feature-readme-instructions has no upstream branch.
To push the current branch and set the remote as upstream, usegit push --set-upstream origin feature-readme-instructionsTo have this happen automatically for branches without a tracking
upstream, see 'push.autoSetupRemote' in 'git help config'.~/C/g/demo-repo  on feature-readme-instructions - at 00:10:33 
> git push -u origin feature-readme-instructions 
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 10 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 388 bytes | 388.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
remote: 
remote: Create a pull request for 'feature-readme-instructions' on GitHub by visiting:
remote:      https://github.com/KrisQK/demo-repo/pull/new/feature-readme-instructions
remote: 
To github.com:KrisQK/demo-repo.git* [new branch]      feature-readme-instructions -> feature-readme-instructions
branch 'feature-readme-instructions' set up to track 'origin/feature-readme-instructions'.~/C/g/demo-repo  on feature-readme-instructions 
> git checkout main                             
Switched to branch 'main'
Your branch is behind 'origin/main' by 2 commits, and can be fast-forwarded.(use "git pull" to update your local branch)~/Code/gitlea/demo-repo  on main <2 ------------- at 00:37:23 
> git pull          
Updating 756290f..cb523b2
Fast-forwardREADME.md | 4 ++++1 file changed, 4 insertions(+)~/Code/gitlea/demo-repo  on main ------- took 6s  at 00:37:52 
> git branch~/Code/gitlea/demo-repo  on main ------ took 15s  at 00:38:41 
> git branch -d feature-readme-instructions 
Deleted branch feature-readme-instructions (was e1737de).~/Code/gitlea/demo-repo  on main ---------------- at 00:38:48 
> git branch~/Code/gitlea/demo-repo  on main ---------------- at 00:38:56 
> ~/Code/gitlea/demo-repo  on main ---------------- at 00:38:57 
> git checkout -b quik-test
Switched to a new branch 'quik-test'~/Code/gitlea/demo-repo  on quik-test ----------- at 00:40:11 
> git status
On branch quik-test
nothing to commit, working tree clean~/Code/gitlea/demo-repo  on quik-test ----------- at 00:41:07 
> git status
On branch quik-test
Changes not staged for commit:(use "git add <file>..." to update what will be committed)(use "git restore <file>..." to discard changes in working directory)modified:   index.htmlno changes added to commit (use "git add" and/or "git commit -a")~/Code/gitlea/demo-repo  on quik-test !1 -------- at 00:41:15 
> git diff~/C/gitlea/demo-repo  on quik-test !1 - took 23s  at 00:41:52 
> git commit -am "added world"
[quik-test f02e2b1] added world1 file changed, 2 insertions(+), 1 deletion(-)~/Code/gitlea/demo-repo  on quik-test ----------- at 00:43:16 
> git diff                    ~/Code/gitlea/demo-repo  on quik-test ----------- at 00:50:44 
> git checkout master
error: pathspec 'master' did not match any file(s) known to git~/Code/gitlea/demo-repo  on quik-test ----------- at 00:52:56 
> git checkout main  
Switched to branch 'main'
Your branch is up to date with 'origin/main'.~/Code/gitlea/demo-repo  on main ---------------- at 00:53:00 
> git brach
git: 'brach' is not a git command. See 'git --help'.The most similar command isbranch~/Code/gitlea/demo-repo  on main ---------------- at 00:53:36 
> git branch~/Code/gitlea/demo-repo  on main ---------------- at 00:53:47 
> git checkout quick-test
error: pathspec 'quick-test' did not match any file(s) known to git~/Code/gitlea/demo-repo  on main ---------------- at 00:54:07 
> git status
On branch main
Your branch is up to date with 'origin/main'.nothing to commit, working tree clean~/Code/gitlea/demo-repo  on main ---------------- at 00:55:20 
> git commit -am "added there"
[main da2bbad] added there1 file changed, 2 insertions(+), 1 deletion(-)~/Code/gitlea/demo-repo  on main >1 ------------- at 00:55:56 
> git checkout quik-test 
Switched to branch 'quik-test'~/Code/gitlea/demo-repo  on quik-test ----------- at 00:56:03 
> git diff main ~/Code/gitlea/demo-repo  on quik-test - took 11s  at 00:56:24 
> git merge main 
Auto-merging index.html
CONFLICT (content): Merge conflict in index.html
Automatic merge failed; fix conflicts and then commit the result.~/Code/gitlea/demo-repo  on quik-test merge ~1 -- at 00:56:30 
> git status
On branch quik-test
You have unmerged paths.(fix conflicts and run "git commit")(use "git merge --abort" to abort the merge)Unmerged paths:(use "git add <file>..." to mark resolution)both modified:   index.htmlno changes added to commit (use "git add" and/or "git commit -a")~/Code/gitlea/demo-repo  on quik-test merge ~1 -- at 01:00:50 
> git diff~/C/g/demo-repo  on quik-test merge ~1 - took 6s  at 01:01:29 
> git commit -am "updated with main"
[quik-test bc3229d] updated with main~/Code/gitlea/demo-repo  on quik-test ----------- at 01:01:55 
> ~/Code/gitlea/demo-repo  on quik-test !1 -------- at 01:02:52 
> git status
On branch quik-test
Changes not staged for commit:(use "git add <file>..." to update what will be committed)(use "git restore <file>..." to discard changes in working directory)modified:   README.mdno changes added to commit (use "git add" and/or "git commit -a")~/Code/gitlea/demo-repo  on quik-test !1 -------- at 01:03:07 
> git add README.md ~/Code/gitlea/demo-repo  on quik-test +1 -------- at 01:03:14 
> git status
On branch quik-test
Changes to be committed:(use "git restore --staged <file>..." to unstage)modified:   README.md~/Code/gitlea/demo-repo  on quik-test +1 -------- at 01:03:21 
> git reset
Unstaged changes after reset:
M       README.md~/Code/gitlea/demo-repo  on quik-test !1 -------- at 01:04:33 
> git status
On branch quik-test
Changes not staged for commit:(use "git add <file>..." to update what will be committed)(use "git restore <file>..." to discard changes in working directory)modified:   README.mdno changes added to commit (use "git add" and/or "git commit -a")~/Code/gitlea/demo-repo  on quik-test !1 -------- at 01:04:50 
> git add README.md ~/Code/gitlea/demo-repo  on quik-test +1 -------- at 01:06:18 
> git commit -m "added install step"   
[quik-test 9d98358] added install step1 file changed, 2 insertions(+), 1 deletion(-)~/Code/gitlea/demo-repo  on quik-test ----------- at 01:06:53 
> git status
On branch quik-test
nothing to commit, working tree clean~/Code/gitlea/demo-repo  on quik-test ----------- at 01:06:59 
> git reset~/Code/gitlea/demo-repo  on quik-test ----------- at 01:07:09 
> ~/Code/gitlea/demo-repo  on quik-test ----------- at 01:07:55 
> git status
On branch quik-test
nothing to commit, working tree clean~/Code/gitlea/demo-repo  on quik-test ----------- at 01:08:00 
> git commit -m "added install step"
On branch quik-test
nothing to commit, working tree clean~/Code/gitlea/demo-repo  on quik-test ----------- at 01:08:24 
> git reset HEAD~1
Unstaged changes after reset:
M       README.md~/Code/gitlea/demo-repo  on quik-test !1 -------- at 01:08:41 
> git status
On branch quik-test
Changes not staged for commit:(use "git add <file>..." to update what will be committed)(use "git restore <file>..." to discard changes in working directory)modified:   README.mdno changes added to commit (use "git add" and/or "git commit -a")~/Code/gitlea/demo-repo  on quik-test !1 -------- at 01:08:56 
> git diff~/Code/gitlea/demo-repo  on quik-test !1 -------- at 01:09:02 
> git log~/C/g/demo-repo  on quik-test !1 --- took 1m 17s  at 01:10:39 
> git reset f02e2b173e2b4975f13e8495f1d5e569d438dcd0
Unstaged changes after reset:
M       README.md
M       index.html~/Code/gitlea/demo-repo  on quik-test !2 -------- at 01:11:04 
> git log~/C/gitlea/demo-repo  on quik-test !2 - took 39s  at 01:12:06 
> git reset --hard cb523b2177a7c45c672e088912df6f8e6bd95b65
HEAD is now at cb523b2 Merge pull request #1 from KrisQK/feature-readme-instructions~/Code/gitlea/demo-repo  on quik-test ----------- at 01:12:35 
> 

🌟

在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/238555.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

8、内部FLASH模拟EEPROM实验(STM32F407)

STM32编程方式 在线编程&#xff08;ICP,In-Circuit Programming&#xff09;: 通过JTAG/SWD协议或者系统加载程序(Bootloader)下载用户应用程序到微控制器中。 在程序中编程(IAP,In Application Programming):通过任何一种通信接口(如IO端口,USB,CAN,UART,I2C,SPI等)下载程…

[论文阅读]Sparse Fuse Dense

SFD Sparse Fuse Dense: Towards High Quality 3D Detection with Depth Completion 论文网址&#xff1a;SFD 论文代码&#xff1a;SFD 论文简读 本文主要关注如何利用深度完成技术提高三维目标检测的质量。论文提出了一种名为 SFD&#xff08;Sparse Fuse Dense&#xff0…

iOS简单理解区分MVC、MVP、MVVM

MVC、MVP、MVVM 前言 这篇文章简单介绍MVC、MVP和MVVM三种架构&#xff0c;并配上一个简单的Swift demo来区分MVC和MVVM两种架构。 MVC 传统MVC 下图是传统结构MVC&#xff0c;可以看到这种结构是紧耦合的&#xff0c;不推荐使用。 苹果的MVC 如下图&#xff0c;这是苹果…

AWS Remote Control ( Wi-Fi ) on i.MX RT1060 EVK - 1 “建立开发环境”

这个系列的文章将叙述如何借由 NXP 的“evkmimxrt1060_aws_remote_control_wifi_nxp”这支 Sample Code&#xff0c;达到 NXP RT1060EVK 经由 U-Blox EVK-JODY-W263 将资讯传到 AWS 上&#xff0c;并可借由手机对 RT1060 EVK 的 LED 进行远端控制。 整体架构如下图所示&#x…

漏洞扫描服务是什么

漏洞扫描服务是维护网络安全的重要一环。通过定期或实时的漏洞扫描&#xff0c;组织可以及时发现并修复可能存在的安全威胁&#xff0c;增强自身网络的安全性。在选择漏洞扫描服务时&#xff0c;需要明确自身的需求和目标&#xff0c;并选择合适的工具和服务提供商。只有这样&a…

TZOJ 1386 十转换转R进制

答案&#xff1a; #include<stdio.h> char fun(int n) {if (n > 0 && n < 10) //如果是小于10进制的return n 48; //ASCII值48else if (n > 10 && n < 16) //如果是大于10进制小于16进制的return n 55; //ASCII值55elseretur…

《微信小程序开发从入门到实战》学习三十八

4.2 云开发JSON数据库 4.2.9 条件查询与查询指令 在查询数据时&#xff0c;有时需要对查找的数据添加一些限定条件&#xff0c;只获取满足给定条件的数据&#xff0c;这样的查询称为条件查询。 可以在集合引用上使用where方法指定查询条件&#xff0c;再用get方法&#xff0…

28.线段树与树状数组基础

一、线段树 1.区间问题 线段树是一种在算法竞赛中常用来维护区间的数据结构。它思想非常简单&#xff0c;就是借助二叉树的结构进行分治&#xff0c;但它的功能却非常强大&#xff0c;因此在很多类型的题目中都有它的变种&#xff0c;很多题目都需要以线段树为基础进行发展。…

SpringBoot结合easyexcel处理Excel文件

原创/朱季谦 假如有这样一个需求&#xff0c;每天需要读取以下表头的Excel文件&#xff0c;统计文件里击中黑名单的比例&#xff0c;该文件is_blacklist列的1表示击中了黑名单&#xff0c;0表示未击中黑名单。 基于该需求&#xff0c;可以在定时任务通过easyexcel工具进行处理…

通过adb命令查看当前界面的Activity

1、先进入shell 2、输入如下命令 dumpsys activity | grep "mFoc"执行效果如下&#xff1a; 从上图可以看到当前正在运行app的进程名称和当前显示的Activity完整路径类名。

Spring AOP 代码案例

目录 AOP组成 通知的具体方法类型 引入Spring AOP依赖 定义AOP层 UserController Postman测试 AOP工作流程 AOP组成 切面 : 切⾯&#xff08;Aspect&#xff09;由切点&#xff08;Pointcut&#xff09;和通知&#xff08;Advice&#xff09;组成&#xff0c;它既包含了…

第九节HarmonyOS 常用基础组件-Text

一、组件介绍 组件&#xff08;Component&#xff09;是界面搭建与显示的最小单位&#xff0c;HarmonyOS ArkUI声名式为开发者提供了丰富多样的UI组件&#xff0c;我们可以使用这些组件轻松的编写出更加丰富、漂亮的界面。 组件根据功能可以分为以下五大类&#xff1a;基础组件…