git总结

一、常用

1.获取用户钥匙:
生成公钥:
git config --global user.name “Your Name”
git config --global user.email “you@example.com”
ssh-keygen -t cj -C “your_email@example.com”

连接线上地址:git remote add origin "线上仓库地址"
连接不上时进行:git init
2.克隆项目:git clone 文件路径
3.拉取代码:git pull
4.提交代码:
1)git add .
2)git commit -m ‘备注信息’
3)git push
指定:
1)git add .
2)git commit -m ‘备注信息’
3)git remote add origin git@github.com:zhaosq8/appium_demo.git
4)git pull origin master
5)git push -u origin master

二、扩展

1.多个远程仓库的使用
多个远程仓库在项目中很少使用,但Git本身是支持的。
那让我们跟着一个案例来温习一下Git命令吧:案例代码已经在Github中托管了,现在要增加Gitee远程仓库。
(1)查看远程仓库
先来查看下当前项目的远程仓库
git remote
不出意外,应该会输出:
origin
这个origin就是一个指向远程仓库的名称,是你在clone时 git 为你默认创建的。
可以通过命令查看origin指向的远程仓库地址:
git remote -v
输出结果:
origin https://github.com/gozhuyinglong/blog-demos.git (fetch)
origin https://github.com/gozhuyinglong/blog-demos.git (push)
该命令会显示读写远程仓库的名称和地址,我这里指向的是Github。
(2)远程仓库重命名
既然这个地址是Github,为了好识别,就将名称改成 github 吧。输入命令:
git remote rename <old_remote> <new_remote>
git remote rename origin github
输入查看远程仓库命令,验证下是否成功,输出结果:
github https://github.com/gozhuyinglong/blog-demos.git (fetch)
github https://github.com/gozhuyinglong/blog-demos.git (push)
成功!
(3)添加另一个远程仓库
下面我们再添加Gitee上的远程仓库,首先在Gitee上创建一个空的仓库,名称与Github上相同。
然后在【克隆/下载】处复制地址。
输出添加远程仓库命令:
git remote add
git remote add github https://github.com/zhaosq8/appium_demo.git
再来验证下是否成功,输出结果:
gitee https://gitee.com/gozhuyinglong/blog-demos.git (fetch)
gitee https://gitee.com/gozhuyinglong/blog-demos.git (push)
github https://github.com/gozhuyinglong/blog-demos.git (fetch)
github https://github.com/gozhuyinglong/blog-demos.git (push)
成功~~~
(4)多个远程仓库的推送/拉取
有了多个远程仓库,推送和拉取再也不能像以前那样git push和git pull了,必须得加上远程仓库的名称,以识别操作的是哪个远程仓库。命令如下:
git push 、git pull :
git push github main
git pull github main
git push gitee main
git pull gitee main
如果不想每次操作都带着分支,需要将本地分支与远程分支进行关联:
git branch --set-upstream-to=/<remote_branch> <local_branch>
git branch --set-upstream-to=gitee/main main
关联后就可以不指定分支了
git push github
git pull github
git push gitee
git pull gitee
(5)移除一个远程仓库
如果想要移除一个远程仓库,可以使用下面命令:
git remote remove 或git remote rm
git remote remove gitee
执行移除远程仓库后,该仓库在本地的所有分支与配置信息也会一并删除

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值