git本地与github仓库文件同步

本地准备工作

  • 下载、安装git
  • 绑定用户
$ git config --global user.name "Your Name"
$ git config --global user.email "[email protected]"
  • 配置 SSH
$ ssh-keygen -t rsa -C "[email protected]"

在GitHub创建仓库

Create repository

同步

  • 克隆远程仓库
git clone https://github.com/***/Linear.git
  • 进入克隆的仓库,进行初始化
git init
  • 如果不包含readme.md,则创建并上传README.md文件
$ git init
$ touch README.md
$ git add README.md
$ git commit -m 'first_commit'
$ git remote add origin https://github.com/***/Linear.git
$ git push origin master
  • 跟踪项目文件夹中的所有文件和文件夹
$ git add .
  • 输入本次的提交说明
$ git commit -m 'this_commit'
  • 关联远程仓库
$ git remote add origin https://github.com/***/Linear.git

origin为远程仓库名,是Git的默认叫法,也可以为别的。

  • 若出现错误 fatal: remote origin already exists,则执行以下语句再关联
$ git remote rm origin
  • 把本地库的所有内容推送到远程库上
$ git push -u origin master
  • 如果在推送时出现错误 error:failed to push som refs to.......,则执行下列语句
$ git pull origin master

将远程库中的内容拉下来再重新推送上去

猜你喜欢

转载自www.cnblogs.com/rookieveteran/p/12639374.html