本地Git搭建并与Github连接

时间:2023-03-09 07:46:10
本地Git搭建并与Github连接

本地Git搭建并与Github连接

git
小结

1.ubuntu下安装git环境

  • ubuntu 16.04已经自带git ,可以通过下列命令进行安装与检测是否成功安装
  1. sudo apt-get inst all git  //安装  

  2. //git命令出现代表安装成功(为考证) 

  3. root@forest-E351:/# git 

  4. usage: git [--version] [--help] [-C <path>] [-c name=value] 

  5. [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path] 

  6. [-p | --paginate | --no-pager] [--no-replace-objects] [--bare] 

  7. [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>] 

  8. <command> [<args>] 


  9. These are common Git commands used in various situations: 


  10. start a working area (see also: git help tutorial) 

  11. clone Clone a repository into a new directory 

  12. init Create an empty Git repository or reinitialize an existing one 

  • 打通本地git与github之间的连接

    设置git的user.name和user.email,便于后面定位git commit的操作对象,姓名和邮箱不需要与github对应,若不操作,则不能进行本地git commit提交。
  1. git config --global user.name "我填写的是github上用户名称" 

  2. git config --global user.email "我填写github注册邮件" 

  • 生成ssh key,用于本地连接上github
    • 查看是否已经有了ssh密钥:cd ~/.ssh,如果没有密钥则不会有此文件夹,有则备份删除。
    • 生存密钥:$ ssh-keygen -t rsa -C “h××@163.com”

      注:ssh-keygen - 生成、管理和转换认证密钥

      ssh-keygen [-q] [-b bits] -t type [-N new_passphrase] [-C comment] [-foutput_keyfile]

      -t 指定要创建的密钥类型。可以使用:“rsa1”(SSH-1) “rsa”(SSH-2) “dsa”(SSH-2)

      -C 提供一个新注释 查看公钥文件,最后就是你-C填写的邮箱

      按3个回车,密码为空,最后得到了两个文件:id_rsa和id_rsa.pub,终端会出现如下结果:
  1. Your identification has been saved in /home/forest/.ssh/id_rsa. 

  2. Your public key has been saved in /home/forest/.ssh/id_rsa.pub. 

  3. The key fingerprint is: 

  4. ……………… 

  5. cat ~/.ssh/id_rsa.pub 

  6. ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQD1MLePx7 

  7. 1IVRowCGKXon1Ucv1xHx//zPO1otu617ru2vLr2kG9rwXOlwYwSV3c 

  8. bH5Ux44yVJiWd+fr7n+re91XYZCa88iY70TSW/9 h××@163.com 

  • 多次生成秘钥会使得目录下自动生成另外一种命名公钥和私钥,如y和y.pub

  • 上传public key到Github账户

    1.登陆github

    2.点击右上方的accounting settings

    3.选择SSH KEY

    4.点击添加ssh key 即为~/.ssh/id_rsa.pub 中的内容

    修改~/.ssh/config Host github.com Hostname ssh.github.com Port 44

    不修改也可以 直接使用ssh -T git@github.com 测试即可,出现以下结果说明连接成功

  1. Hi wowforestwow! You've successfully authenticated,  

  2. but GitHub does not provide shell access. 

  3. Connection to github.com closed