代码上传到github,gitlab等git仓库进行托管

1、以github为例,首先创建账号;

2、在github上创建一个代码仓库

3、创建项目名称,如下图:


4、创建完之后,需要ssh key

(1) 在终端输入:ssh-keygen -t rsa -C 'your email@domain.com' //输入你的邮箱,其实默认这个也可以。

(2)终端会提示(Enter file in which to save the key (/Users/gobi/.ssh/id_rsa):  这个时候输入保存rsa文件名。

(3)输入的密码不能太短,这个时候我取名字为hello。

(4)取出hello.pub内的公钥密码,快速找到hello.pub文件 control+空格,然后输入hello.pub 找到文件后用xcode打开,内容大概如下:

ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDgopsXMenmxzusfjbrPB4RRlvdzTVSEzRh66RYDjvH.......(注意如果后面有邮箱的名字去掉);



(5)、首先在github上面选中settings

(6)、将公钥密码放入到下图的key中,title任意输入即可。



    5、将代码上传到github
    (1)首先进入项目的目录:cd 项目的路径(/Users/gobi/Downloads/WorkingCalendar)
    (2)以下git命令
        git init
        git commit -m 'stumansys'
        git remote add origin https://github.com/aimsgmiss/WorkingCalendar
        git push origin master
      (3) 以下是参照别人的,可能会进入vim编辑器,退出按esc键。
    如果执行git remote add origin
       https://github.com/aimsgmiss/WorkingCalendar
    如果出现错误:
      fatal: remote origin already exists
    则执行以下语句:
      git remote rm origin
    再往后执行git remote add origin https://github.com/Flowerowl/stumansys.git 即可。
    在执行git push origin master时,报错:
      error:failed to push som refs to.......
    则执行以下语句:
      git pull origin master
    先把远程服务器github上面的文件拉先来,再push 上去。
    如果出现hint: Updates were rejected because the remote contains work that you do
    hint: not have locally. This is usually caused by another repository pushing
    hint: to the same ref. You may want to first integrate the remote changes
    hint: (e.g., 'git pull ...') before pushing again.
    hint: See the 'Note about fast-forwards' in 'git push --help' for details.
    可以采取暴力的手段:git push origin master -f
    最后大功告成。


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值