git常用命令

基本使用

ssh密钥配置

  1. 生成密钥
    1
    ssh-keygen -t rsa -C "email@qq.com"
  2. 然后将~/.ssh/id_rsa.pub内容拷贝的对应仓库的设置中。

简单提交

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# 在项目路径下初始化仓库
git init

# 添加远程仓库
git remote add origin git@github.com:chengleileilei/dgcl.git

# 添加文件到缓存区、
git add .

# 提交到本地
git commit -m "first commit"

# 提交指定分支到指定的远程仓库
git push origin master:main

# 查看所有分支
git branch --list

# 选择当前分支
git switch branch_name
# or
git checkout branch_name

# 当前分支重命名
git branch -m new_name

# 为当前分支设置对应的上游分支(远程仓库分支),设置后直接git push即可提交
git push --set-upstream origin main
  • 清除缓存
1
git rm -r --cached .
  • 查看仓库文件列表
1
git ls-files