安装git
选择一个文件夹作为git仓库,cd到文件夹输入
c
git init
![](https://i-blog.csdnimg.cn/direct/108a3ccbb50a4324a7f5c5fa0b39b881.png)
文件夹出现.git文件夹,该文件夹默认为隐藏文件夹,设置为不隐藏
在cmd中输入
c
ssh-keygen -t rsa -C "xxx@xxx.com"
该邮箱为github邮箱,然后一路enter出现以下
在本地用户文件夹找到.ssh,打开id_rsa.pub复制获得key
到github创建key
复制刚才本地文件中的key到key中
输入以下添加用户名和邮箱,使用github用户名和邮箱
c
git config user.name "要修改的名字"
c
git config user.email "要修改的邮箱"
关联Git本地仓库和Git远程仓库,origin后为github仓库地址
c
git remote add origin https://github.com/xxx/123.git
添加本文件夹下所有文件到本地仓库
c
git add .
查看当前哪些文件已添加
c
git status
![](https://i-blog.csdnimg.cn/direct/35608d4a21ad44b499819ab982244194.png)
提交到本地仓库
c
git commit -m "upload file"
![](https://i-blog.csdnimg.cn/direct/a5ef5137a37f41c2a8c3f4e578a4f2a3.png)
先尝试push,会弹出github的授权,按步骤授权即可
c
git pull --rebase origin main
将刚刚本地提交的文件上传到远程仓库上,main是分支名字
c
git push origin main
要删除本地仓库直接删除.git文件夹即可
查看所有分支
c
git branch -a
![](https://i-blog.csdnimg.cn/direct/8a41db54dcaa488b97c0579580b48443.png)
切换分支
c
git checkout main
![](https://i-blog.csdnimg.cn/direct/69ee4ef67289418dbecfbfb44d32d065.png)
查看日志,由上到下为最新到最旧的log commit后为本次提交的哈希值
c
git log
![](https://i-blog.csdnimg.cn/direct/5b301b0b31fa4c0492b2b589ecc04048.png)
查看所有远端仓库
c
git remote -v
切换本地和远端仓库关联
c
git remote set-url origin https://github.com/xx/xx.git (新地址)
从远端仓库拉取文件到本地仓库,除了REDEME以外都会拉取下来
c
git pull
![](https://i-blog.csdnimg.cn/direct/d8a90e5659f4466fa5442aa4b708f901.png)
回滚提交,可以通过git log查看某一提交操作的哈希值,本回滚为指定哈希值事件的逆操作
c
git revert <commit-hash>