Git常用命令

87 阅读1分钟

1.git clone 指定远程分支(git clone 默认拉取master分支)

git clone -b dev https://gitee.com/test/qqw.git

2.本地已有项目下拉取远程分支

git checkout -b dev origin/dev

3.更新某分支的内容

git pull origin dev

4.合并代码到某分支

#在alpha分支进行合并dev分支
git merge dev

5.代码commit了如何反提交(备注:本操作在idea中进行)

#视频链接
https://www.bilibili.com/video/BV161421C7zx/?vd_source=d6746649fc56025c46f587b0c3eb526b
#情景1
代码commit 没有push到仓库 idea中点击操作 undo commit 
#情景2
代码commit push到仓库 revert commit 本地撤回 push 同步远程仓库 cherry-pick undo commit 本地代码还原,显示没有提交

6.git worktree(根据项目复杂度考虑是否使用)

https://blog.csdn.net/weixin_36757282/article/details/128712125

7.git查看remote与修改remote地址

#参考链接
https://blog.csdn.net/qq_63964907/article/details/144566103
https://blog.csdn.net/CoderSharry/article/details/131531402
https://blog.csdn.net/xutong_123/article/details/128021440

#修改remote地址
git remote set-url origin http://[ip address]/peoject_name.git/

#查看remote地址
git remote -v
origin  https://gitee.com/arhi/server.git (fetch)
origin  https://gitee.com/arhi/server.git (push)

#添加remote
git remote add origin git@github.com:***.git

#推送到指定的remote的指定分支
git push -u origin master

8.配置ssh公钥

#参考链接
https://devpress.csdn.net/linux/66cfeebf0bfad230b8b104a1.html

git config --global user.name "Arhi"
git config --global user.email "e26074395025@163.com"
ssh-keygen -m PEM -t rsa -C 'e26074395025@163.com'
ssh-agent -s   ## 把私钥信息放到公钥中
cat ~/.ssh/id_rsa.pub
ssh -T git@gitee.com