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 ”这几个字。

 
posted @ 2014-06-11 15:17  残虾寄居所  阅读(169)  评论(0编辑  收藏  举报