使用git上传项目到GitHub

【第一步】建立先仓库

  第一步的话看一般的提示就知道了,在github新建一个repository(谷歌可以解决),都是可视化的界面操作,所以难度不大。或者看这里:https://help.github.com/articles/create-a-repo 这是官方help,虽然是英文的,但是基本都是图和代码,所以很容易读懂。

  在github首页的右上角,点击红框中的Create New Repo。 
  进入新建仓库的界面   
  填一下仓库名称,Initialize this repository with a README是可选的,不过本人建议最好选上,可以在后面省一个步骤。填好之后,点Create repository就行了。

【第二步】克隆仓库

git clone https://github.com/hlk-1135/SSH_PersonInformation.git
 
 
  • 1

【第三步】上传README.md文件

  这个时候,我们的GitHub文件夹下就多了一个SSH_PersonInformation文件夹,进入文件夹目录,对仓库进行初始化,如果我们之前没有勾选创建README,则要先创建README.md文件,不然上传文件会报错。如果在第一步就勾选过了,则可以直接进入第四步。

复制代码 
 

 git init
 touch README.md
 git add README.md
 git commit -m 'first_commit'
 git remote add origin https://github.com/hlk-1135/SSH_PersonInformation.git
 
 
  • 1
  • 2
  • 3
  • 4
  • 5

【第四步】push文件

创建完README.md后,就可以push了,代码类似。 

git add .
git commit -m 'first_commit'
git remote add origin https://github.com/hlk-1135/SSH_PersonInformation.git
 
 
  • 1
  • 2
  • 3

如果执行

git remote add origin 
https://github.com/hlk-1135/SSH_PersonInformation.git

,出现错误:

fatal: remote origin already exists
 
 
  • 1

则执行以下语句:

git remote rm origin
 
 
  • 1

再往后执行

git remote add origin 
https://github.com/hlk-1135/SSH_PersonInformation.git

即可。

在执行git push origin master时,报错:

error:failed to push som refs to…….

则执行以下语句:

git pull origin master

先把远程服务器github上面的文件拉先来,再push 上去。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值