- 作者: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.md
no 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 readme
1 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, use
git push --set-upstream origin feature-readme-instructions
To 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-forward
README.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.html
no 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 world
1 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 is
branch
~/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 there
1 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.html
no 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.md
no 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.md
no 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 step
1 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.md
no 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
>