push代码到github省略用户名和密码

本文详细介绍了如何使用SSH及HTTPS两种方式将本地代码推送到GitHub远程仓库,并比较了这两种方式在命令行操作上的区别。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、需要在github的Account settings中关联本地ssh公钥,方法参考如下网址:

设置ssh登陆远程仓库

使用HTTPS需要每次输入密码,SSH则不用,但SSH需要配置密钥 。

二、命令行的区别:

1. 采用https:

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/guochy2012/test.git
git push -u origin master

Push an existing repository from the command line

git remote add origin https://github.com/cyrion/test.git
git push origin master

2. 采用SSH:

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 git@github.com:cyrion/test.git
git push -u origin master

Push an existing repository from the command line

git remote add origin git@github.com:cyrion/test.git
git push origin master

补充说明:

把本地库的内容推送到远程,用git push命令,实际上是把当前分支master推送到远程。

当第一次建立远程库,远程库为空时,我们第一次推送master分支时,加上了-u参数,Git不但会把本地的master分支内容推送的远程新的master分支,还会把本地的master分支和远程的master分支关联起来,在以后的推送或者拉取时就可以简化命令为

git push origin master

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值