git使用入门

在github.com上 建立了一个小项目,可是在每次push  的时候,都要输入用户名和密码,很是麻烦

原因是使用了https方式 push

在termail里边 输入  git remote -v 

可以看到形如一下的返回结果

origin https://github.com/yuquan0821/demo.git (fetch)

origin https://github.com/yuquan0821/demo.git (push)

下面把它换成ssh方式的。

 

1. git remote rm origin
2. git remote add origin git@github.com:yuquan0821/demo.git

Create a new repository on the command line

touch README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/sunnynut/ztgentle.git
git push -u origin master

Push an existing repository from the command line

git remote add origin https://github.com/sunnynut/ztgentle.git
git push -u origin master

设置SSH

如果要跟GitLab服务器打交道,还要设ssh。

 

在Linux的命令行下,或Windos上Git Bash命令行窗口中(总之不要用iOS),键入:

ssh-keygen -t rsa -C "wukong.sun@xxx.com"

然后一路回车。生成ssh key pair。

如果在Linux上,需要把其中的私钥告诉本地系统:

ssh-add ~/.ssh/id_rsa

再把其中公钥的内容复制到GitLab上。具体方法是:
显示ssh公钥的内容:

cat ~/.ssh/id_rsa.pub

打开GitLab网页,点击“Add SSH Key”,然后把刚才ssh公钥id_rsa.pub的内容paste进去。

要是GitLab报“不是有效的key”之类的错误,可能是你没去除注意去除多余的回车符,也可能是paste之前copy的时候,没copy最开头的“ssh-rsa ”这几个字。

 

转载于:https://www.cnblogs.com/ztgentle/p/3782050.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值