Linux & Git常见命令(自用版)
Linux & Git等常见命令
本篇记录一下平时用到的常见命令
1 Linux
2 Git
2.1 配置身份
在仓库内配置提交身份,只影响当前仓库:
1 | git config user.name "用户名" |
检查配置:
1 | git config --get user.name |
若希望所有仓库都使用此身份,加 --global:
1 | git config --global user.name "用户名" |
2.2 配置远程仓库
查看当前远端:
1 | git remote -v |
得到输出,可能只有自己仓的地址
1 | origin https://自己仓的地址 (fetch) |
添加官方仓库:
1 | git remote add upstream https://官方仓库 |
重新查看,可以发现添加上了官方仓库的地址
1 | git remote -v |
获取上游仓库的代码
1 | git fetch upstream |
例如官方主分支是 master:
1 | git switch master |
或者,如果你的本地 master 不需要保留自己的提交,只想完全和官方同步:
1 | git switch master |
然后把最新的 master 推到自己的 fork:
1 | git push origin master |
2.3 初始化
初始化 Git:
1 | git init |
检查:
1 | git status |
然后提交本地代码:
1 | git add . |
接着去 GitCode 网页创建一个同名空仓库,例如:
1 | RTScope |
设置主分支
1 | git branch -M main |
关联 GitCode
1 | git remote add origin https://gitcode.com/freedom178/RTScope.git |
推送
1 | git push -u origin main |
3 Gitcode
增加gitcode的配置信息
1 | read -rp "GitCode 用户名: " GITCODE_USER |
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 Earnshawn!
评论





