自己使用的一些脚本,放到github可以更方便备份和存取.
在windows / wsl 安装github.
如下场景在Windows11/wsl archlinux, 编辑windows d盘工作目录的脚本,同步到github.
git init
git status
git add .
git commit -m ‘init version’
git config
git branch
git push
ssh-keygen
ssh-addkey
ssh
https://github.com/Git-Commands
https://www.youtube.com/watch?v=tRZGeaHPoaw&t=999s
https://www.youtube.com/watch?v=RGOj5yH7evk&t=1553s
如下操作是都在本机, 没有连接到github… 对文件的修改,提交,restore, 都在本地(.git)目录.
项目名字为 autodg.
本地->staging ->commit.
add , 从本地发放到staging.
commit, 从staging 提交. 提交后别人可见.
this cmd will create .git directory
should show no files.
把当前目录的文件提交到staging阶段.
一个点,是当前目录的所有文件.
shows all files in staging.
commit all files. -m 对这次commit加注释
show no files need to be commited.
create a readme.md files
shows readme.md is untracked.
or just git add .把readme.md加到staging.
shows readme.md can be committed.
把readme提交.
add one line “new line”
修改readme.txt.
shows readme.md is changed.
show the difference between old and new version.
显示增加的一行
restore the old version(with new line)
新加的一行被放弃. 恢复到前一个版本.
查看提交的日志
check all the commits.
git log --oneline 显示简要日志
show simple one line comments
git log -p 显示提交的差异
git help log(get more help of log)
建立分支版本,比如修复bug的分支.
git branch to check all the branches
git switch bugfix , switch to another bransh.
修复后跟主版本合并.(merge)
git merge -m ‘merge with bugfix in t2.sh’ bugfix
merge bugfix branch to master
after bugfix is merged, delete the bugfix branch.
git branch to check it.
删除bugfix这个分支.
create a new branch “newbranch” and switch to it.
建立一个新分支并切换到它
github不支持https密码认证,要用git提交到github,必须建立ssh认证.比如rsa 密钥.
步骤如下 setup ssh authentication.
ssh-keygen
说明ssh已经建好了.
如下把本地的文件上传到github网站.
git remote add origin [email protected]:yourname/autodg.git
git branch -M main
git push -u -f origin main
git push --all (all branches)
[nome@LIYUEFU-T14 src-test]$ git push -u origin main
Username for ‘https://github.com’: [email protected]
Password for ‘https://[email protected]@github.com’:
remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for ‘https://github.com/yourname/autodg.git/’
使用ssh链接,而不是https链接. 需要先建立ssh密钥. 参看上面.
git remove origin
删除https的链接
git remote add origin [email protected]:yourname/autodg.git
使用ssh的链接
重新push
############error fix###############
[nome@LIYUEFU-T14 autodg]$ git push -u origin main
To github.com:yourname/autodg.git
! [rejected] main -> main (non-fast-forward)
error: failed to push some refs to ‘github.com:yourname/autodg.git’
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. If you want to integrate the remote changes,
hint: use ‘git pull’ before pushing again.
hint: See the ‘Note about fast-forwards’ in ‘git push --help’ for details.
使用-f 选项.
[nome@LIYUEFU-T14 autodg]$ git push -f -u origin main
Enumerating objects: 76, done.
Counting objects: 100% (76/76), done.
Delta compression using up to 16 threads
Compressing objects: 100% (71/71), done.
Writing objects: 100% (76/76), 82.41 KiB | 102.00 KiB/s, done.
Total 76 (delta 10), reused 0 (delta 0), pack-reused 0 (from 0)
remote: Resolving deltas: 100% (10/10), done.
To github.com:yourname/autodg.git