git使用

  • 获取密钥
ssh-keygen -t rsa -C "uesr@gmail.com"//填写email地址,然后一直“回车

登陆github,点击右上角的 Account Settings--->SSH Public keys ---> add another public keys
把你本地生成的密钥复制到里面(key文本框中), 点击 add key 就ok了

  • 测试连接
$ ssh -T git@github.com

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

  • 设置用户信息
$ git config --global user.name "uesrname"//给自己起个用户名
$ git config --global user.email  "uesr@gmail.com"//填写自己的邮箱

创建项目

  • 在github上创建项目
填写项目信息:
project name: hello world
description : my first project
点击“Create Repository” ; 现在完成了一个项目在github上的创建。
  • 在本地创建相同的项目
$ 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:user/hello-world.git   //连接远程github项目  
$ git push -u origin master   //将本地项目更新到github项目上去
现在查看github上面的hello world 项目,是不是发现已经将本地中的README文件更新上来了。 :) 恭喜!

可能出现的问题

  1. 在执行
    $ git remote addorigin git@github.com:user/hello-world.git
    错误提示:fatal: remote origin already exists.
    解决办法
    $ git remote rm origin
    然后在执行:$ git remote add origin git@github.com:user/hello-world.git就不会报错误了

  2. 在执行
    $ git push origin master
    错误提示:error:failed to push som refs to.......
    解决办法:
    $ git pull origin master//先把远程服务器github上面的文件拉下来,再push 上去。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 本文作者陈云峰,转载请注明。 这篇文章记录个人常用的一些命令,和记不住的一些命令,转载了并不断更新。 Git官网 ...
    陳云峰阅读 2,846评论 0 24
  • 首先确定电脑安装了git 输入git会产生提示: 如果没有安装,那么就网上搜索下载完成安装. 可以使用命令行安装,...
    元宇宙协会阅读 4,499评论 1 9
  • 声明:这篇文章来源于廖雪峰老师的官方网站,我仅仅是作为学习之用 Git简介 Git是什么? Git是目前世界上最先...
    横渡阅读 3,987评论 3 27
  • 原文地址主要用到的命令: git config user.name 设置用户名 git config user....
    AFinalStone阅读 488评论 0 2
  • 昨天在同事电脑上操作了一把cherry-pick代码,发现很多功能不用,就慢慢忘记了,梳理了下流程图: git c...
    gogoingmonkey阅读 691评论 0 0