Github学习记录

参考:
ubuntu下github教程  http://blog.csdn.net/a657941877/article/details/9570745
GitHub详细教程  http://blog.csdn.net/lvdezhou/article/details/50380235

 [创建SSH密钥]
这个密钥用来跟 github 通信,在本地终端里生成然后上传到 github;
   1、创建SSH密钥
    本地操作:
   (1)打开终端,输入命令 ssh-keygen -t rsa -C "youremail@163.com" 然后按回车键
   (2)按回车保存到默认位置,再稍等出来提示输入passphrase,一共要输两遍;它用来加密私钥,也就是以后使用私钥的时候要输这个密码;
   (3)稍等出来提示成功,密钥存放在自己主文件夹的.ssh文件夹中;
      在~/.ssh/下可以查看设置好的公钥/私钥

      使用命令
      cd ~/.ssh
      ls


   可以看到id_rsa(私钥)    id_rsa.pub(公钥) 
   远端操作:
登录github,点击头像下拉菜单,进入settings/SSH Keys
将id_rsa.pub中的内容粘贴到Key中

  [获取他人的版本库]
       从GitHub服务器复制一个版本库到本地:
mkdir git
mkdir repos
cd git/repos
git clone git@github.com:"account context"/"repos name".git


  [库的创建与文件上传]
    1、远端操作:通过github个人主页Create New Repository
    2、本地操作:
(1). 进入项目目录,使用git init
      ## 若想删除已有的.git 文件: 
使用命令  rm -r .git
(2). 创建别名
 git  remote add jos https://github.com/acDante/jos.git
以后就可以使用"jos"代替后面的URL
(3). 上传文件
添加文件         git add file
        特别 git  add . (.代表整个文件夹)
提交到本地库  git commit -a -m "content"    
//content为注释内容,表明本次修改了哪些地方
    提交到远程github库 
    git push jos master      (jos:为远端库的别名  master:分支名)

   # 使用Git push提交到远端库时遇到的问题及解决方法 #
1. 错误提示:
dxt@dxt:~/Homework/src/lab1_1$ git push -u jos master
Username for 'https://github.com': acDante
Password for 'https://acDante@github.com': 
To https://github.com/acDante/jos.git
  ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/acDante/jos.git'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes (e.g. 'git pull') before pushing again.  See the
'Note about fast-forwards' section of 'git push --help' for details.
  
   错误原因: 当前本地库不是最新的,需要更新。
   解决方法: 先使用 git pull (库名) (分支名) 再使用git push

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值