Git 入门级常用命令,基础简明教程。
配置Git
在本地创建 ssh key,并添加到 Github
1ssh-keygen -t rsa -C "[email protected]"
2
3生成后,复制 id_rsa.pub 内容,添加到 Github
4
5位置:github上 → Account Settings → SSH Keys → Add SSH Key
6
生成本地用户
1git config --global user.name "your name"
2git config --global user.email "[email protected]"
将本地仓库提交到 Github
1git init # 初始化
2git add . # 添加所有文件
3git commit -m "begin" # 提交并备注信息
4git branch -m "main" # 将本地默认分支修改为 main
5
6# 链接远程仓库
7git remote add origin [email protected]:yourName/yourRepo.git
8
9git push -u -f origin main # 将本地分支推送到远程仓库,强制覆盖远程主分支内容
10
11
12git fetch # 从远程仓库下载新分支与数据
13git merge # 从远程仓库提取数据并尝试合并到本地分支
14
其他常用命令
1git clone [email protected]:yourName/yourRepo.git ./ #将远程仓库拉取到当前文件夹
2
3
4# 将本地的状态回退到和远程一致
5git fetch origin
6git reset --hard origin/main
7
8# 清除缓存
9git rm -r --cached .
10
评论