git常用操作:本地代码提交到远程github

(1)在提交之前,你本地代码先backup!!!

(2)github先建仓库

  去https://github.com登录账户去创建仓库helloworld(你代码工程名字),你本地的文件比如helloworld里面的文件会进入这个文件夹里面

  生成仓库地址比如:https://github.com/shoneSolomon/helloworld.git
 

(3)本地仓库关联GitHub仓库:remote add origin 

在项目到根目录下比如进入helloworld,以下用到的name和email是你GitHub或者GitLab注册时候的name和邮箱
git init 
git config
--global user.name "xxx"
git config
--global user.email "xxx@qq.com"
git config --global http.sslVerify false(如果有fatal: unable to access 'https://git.chaomy.com/victor/datasets-backend.git/':
      SSL certificate problem: certificate has expired 问题,简单屏蔽的话)
git remote add origin https://github.com/shoneSolomon/helloworld.git git add * git commit -m "提交的简单描述" origin 代表项目仓库地址 master 代表主分支
develop 代表开发分支

 

(4)任何提交之前先拉:pull

  git pull origin master --allow-unrelated-histories 
 

(5)提交代码到远程GitHub仓库:push

  git push -u origin master 
 

(6)总结基本流程:

  基本流程:init=> config=> remote add origin => pull =>push 记住它用的时候前面统一加git

(7)切换代码库地址和切换分支

  git remote -v 查看远程分支  
  git remote rm origin 删除远程origin 
  git remote add origin http://mmmmmmmm.git(新git地址)   
 
  git checkout -b develop 检出并且切换到开发分支  
  git push origin develop 推送到远程开发分支

(8)提交注意事项和提交错误后版本回退

  提交之前删除pyc文件:
  find . -name "*.pyc"| xargs rm -rf
 
  删除某个文件:
  git rm hello.txt
  git commit -m "rm hello.txt"
 
  一旦出现误删除版本回退:
  git reflog 查看最近提交版本
  git reset --hard 084c65c 回退
 
 
posted @ 2018-05-26 13:31  Adamanter  阅读(137)  评论(0编辑  收藏  举报