发布于 
阅读: -

Git常用命令

Git常用命令记录

Git基本命令

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
git status                                查看仓库的状态
git init 初始化Git仓库

git add 1.txt 将1.txt添加到Git仓库
git commit -m "text commit" 将1.txt文件提交到Git仓库,-m表示提交信息

git log 查看Git仓库日志

git branch 查看Git仓库的分支情况,master为主分支,*号表示当前所在的分支
git branch a 创建新分支a
git branch -M main 将当前分支重命名为main分支

git checkout a 切换到a分支
git checkout -b b 创建并切换到新分支b

git merge a 将a分支合并到当前分支

git branch -d a 删除a分支
git branch -D a 强制删除a分支

git tag v1.0 为当前分支添加标签v1.0
git tag 查看标签记录
git checkout v1.0 切换到该标签下的代码状态

Git与Github通过ssh进行绑定

使用ssh-keygen -t rsa生成公钥和私钥两个文件id_rsa、id_rsa.pub,
打开github设置,把公钥文件添加SSH and GPG keys页面的SSH keys中。

1
ssh -T git@github.com                    验证绑定是否成功

通过 Git 将代码提交到 GitHub

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
克隆修改并推送到远程仓库
git clone https://github.com/xxx/xxx.git
git add README.md
git commit -m "text commit"
git push origin master

创建并推送一个新的仓库
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/xxx/xxx.git
git push -u origin main

推送到一个已存在的仓库
git remote add origin https://github.com/xxx/xxx.git
git branch -M main
git push -u origin main

本站由 @foyaga 使用 Stellar 主题创建。
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议,转载请注明出处。

本"页面"访问 次 | 👀总访问 次 | 🥷总访客