Git 使用教程 之 Mac 使用Git上传代码到GitHub

1、登陆github,新建一个远程仓库(没有github就新建一个帐号)

1)创建新仓库入口在个人主页

Git 使用教程 之 Mac 使用Git上传代码到GitHub
Git 使用教程 之 Mac 使用Git上传代码到GitHub

2、打开mac终端

1)cd 到需要上传代码的根目录。

Git 使用教程 之 Mac 使用Git上传代码到GitHub

2)初始化git:git init 

Git 使用教程 之 Mac 使用Git上传代码到GitHub

这里提下两个删除命令:rm xxx.xx 删除文件(xxx.xx为文件名字);rm -rf xxx 删除文件夹

3)添加文件到本地仓库:git add .( .为添加整个文件夹,也可以换成某个文件)

4)写更新纪录:git commit -m "xxx"


Git 使用教程 之 Mac 使用Git上传代码到GitHub

5)链接远程仓库(git仓库):git remote add origin https://github.com/xxx(xxx为你的地址)看我下面框出来的地址

Git 使用教程 之 Mac 使用Git上传代码到GitHub


Git 使用教程 之 Mac 使用Git上传代码到GitHub

6)执行pull命令:git pull origin master

当报错:fatal: refusing to merge unrelated histories

新的版本需要添加--allow-unrelated-histories

最终命令行为:git pull origin master --allow-unrelated-histories

7)等待一小会会跳到这个页面问你合并分支的理由

Git 使用教程 之 Mac 使用Git上传代码到GitHub

8)按shift+q,再输入q!即可跳回原来的界面

9)最后一步上传:git push origin master

Git 使用教程 之 Mac 使用Git上传代码到GitHub
Git 使用教程 之 Mac 使用Git上传代码到GitHub