git和github使用整理

来源:互联网 发布:剑三成女女神捏脸数据 编辑:程序博客网 时间:2024/06/07 23:56

Tips:首先不分平台,windows和Mac都一样(暂时没发现有什么区别)

1、安装Git

2、注册并登陆GitHub

3、将Git和GitHub关联起来

____________________________________________________________________________________________________________________________________

我们只讲第三点。。。

ssh密匙是两者关联的纽带

__________________________________________________________________________________________________________________________________

如何获取key

1、进入.ssh目录,查看目录中文件

如果里面有文件,建议清理原ssh密匙

例如:

 $ ls  config id_rsa id_rsa.pub known_hosts $ mkdir key_backup $ cp id_rsa* key_backup $ rm id_rsa*


2、然后获取密匙:

ssh-keygen -t rsa -C "liuhuajian_lhj@163.com"//填写email地址,然后一直“回车”ok
生成的id_rsa.pub文件中的内容,就是ssh密匙

3、讲生成密匙添加到github中:

登陆github,点击右上角的 Settings--->ssh and GPG keys ---> add new public keys即可

____________________________________________________________________________________________

测试是否连接成功

$ ssh -T git@github.com

如果提示:Hi defnngj You've successfully authenticated, but GitHub does not provide shell access. 说明你连接成功了

配置用户信息

1、

$ git config --global user.name "liuhuajian"//给自己起个用户名$ git config --global user.email  "liuhuajian_lhj@163.com" //邮箱

2、

在github中找到 Account Settings--->Account Admin ,找到一下信息:

Your API token is e97279836f0d415a3954c1193dba522f ---keep it secret! Changing your password will

generate a new token

$ git config --global github.user defnngj      //github 上的用户名$ git config --global github.token e97279836f0d415a3954c1193dba522f

____________________________________________________________________________________________


====================创建一个项目========================

 1. 回到github首页,点击页面右下角“New Repository”

填写项目信息:

project name: hello world

description : my first project

点击“Create Repository” ; 现在完成了一个项目在github上的创建。

2. 我们需要使用git在本地创建一个相同的项目。

$ makdir ~/hello-world    //创建一个项目hello-world$ cd ~/hello-world    //打开这个项目$ git init    //初始化 $ touch README$ git add README   //更新README文件$ git commit -m 'first commit'//提交更新,并注释信息“first commit” $ git remote add origin git@github.com:defnngj/hello-world.git   //连接远程github项目  $ git push -u origin master   //将本地项目更新到github项目上去

____________________________________________________________________________________________

------------------------------------关于可能出现的错误----------------------------------

1.在执行

$ git remote addorigin git@github.com:defnngj/hello-world.git

错误提示:fatal: remote origin already exists.

解决办法:

$ git remote rm origin

然后在执行:$ git remote add origin git@github.com:defnngj/hello-world.git 就不会报错误了

 

2. 在执行

$ git push origin master

错误提示:error:failed to push som refs to.......

解决办法:

$ git pull origin master // 先把远程服务器github上面的文件拉下来,再push 上去。


0 0
原创粉丝点击