美文网首页@IT·互联网
使用Git将代码同步至GitHub

使用Git将代码同步至GitHub

作者: dpkBat | 来源:发表于2017-05-17 16:24 被阅读0次

标签:GitHub


配置GitHub

  • 安装git
sudo apt-get install git git-core
  • 验证git是否安装成功
git --version
  • 配置个人GitHub
git config --global user.name "Your Name"  
git config --global user.email "youremail@domain.com" 
  • 创建SSH key

参考Generating a new SSH key and adding it to the ssh-agent

  • 将SSH key添加到Github账号

参考Adding a new SSH key to your GitHub account

常用代码解释

  • 新建一个文件
touch README.md
  • 初始化本地仓库
git init

本地更新同步至Github三步骤

  • 添加文件
#将所有文件添加到本地仓库,等待上传
git add --all
#将指定文件添加到本地仓库
git add v2exSpider.py
  • 提交变更信息
git commit -m "修改了v2exSpider.py,加入爬虫停止url"
  • 推送变更
git push origin master
  • 首次推送还需要与Github仓库建立连接
git remote add origin https://github.com/d4ngy4n/v2exSpider.git

  • 推送项目到Github
#首次推送
git push -u origin +master
#后续推送
git push
  • 复制仓库地址
git clone https://github.com/d4ngy4n/v2exSpider.git
  • 整合远程变更到本地
git pull

新建一个repository

参考Creating a new repository

Repository名称为iApps

将本地的项目上传到GitHub

本地项目的地址:/home/d4ngy4n/git/iApps

  • 在该目录下打开终端
  • 本地上传到Github
git init
  • 将该目录下所有文件加入仓库
git add --all
  • 提交变更
git commit -m "首次提交"
  • 与GitHub仓库连接
git remote add origin https://github.com/d4ngy4n/iApps.git
  • 上传至GitHub仓库
git push -u origin master

一些错误的解决方案

  1. error: 无法推送一些引用到 'https://github.com/d4ngy4n/v2exSpider.git'
    提示:更新被拒绝,因为远程仓库包含您本地尚不存在的提交。这通常是因为另外
    提示:一个仓库已向该引用进行了推送。再次推送前,您可能需要先整合远程变更
    提示:(如 'git pull ...')。
    解决方法:
git push -u origin +master

相关文章

网友评论

    本文标题:使用Git将代码同步至GitHub

    本文链接:https://www.haomeiwen.com/subject/glidxxtx.html