Gith上传文件教程

Git

  • 下载安装git
  • 绑定用户
$ git config --global user.name "Your Name" 
$ git config --global user.email "email@example.com"

配置ssh

  • 查看安装文件目录,是否有.ssh的目录,如果存在查看.ssh目录中是否有id_rsa和id_rsa.pub文件,如果有了,直接到下一步,如果没有,则需要进行免密码登陆的设置:
  • $ ssh-keygen -t rsa -C "youremail@example.com"
  • PS:将id_rsa.pub文件中的内容复制到github网站的setting->SSH and GPG keys->New SSH key中

创建仓库

  • 填一下仓库名称,Initialize this repository with a README是可选的,建议在创建时选上,可以在后面省一个步骤。填好之后,点Create repository完成仓库的建立

上传README 文件

  • 如果没有在创建仓库时勾选README,用以下代码上传
  • $ git init
    $ touch README.md
    $ git add README.md
    $ git commit -m 'first_commit'
    $ git remote add origin git@github.com:wliii/learngit.git
    $ git push origin master

上传文件

  • 关联远程仓库
 $ git remote add origin git@github.com:wliii/learngit.git
  • 将本地内容推送到远程库中
 $ git push -u origin master

常见问题

  • 关联出现错误 fatal: remote origin already exists,则执行下列语句再进行关联
git remote rm origin
  • 推送时出现错误 error:failed to push som refs to…….,则执行下列语句
 git pull origin master

-出现以下错误:
$ git push -u origin master
To git@github.com:xxx/xxx.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to ‘git@github.com:xxx/xxx.git’
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.
问题原因:本地仓库中并没有README.md文件
解决方法:

 $ git stash
 $ git pull --rebase origin master
 $ git push -u origin master

大家加油!!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值