Total Pageviews

Tuesday 2 October 2018

Git使用入门

1.创建一个目录
mkdir <folder>
2.初始化git仓库
进入目录cd <folder>
在目录下git init
3.创建文件
vim file.cpp
git remote add origin https://github.com/username/XXX.git
git add file.cpp
git commit -m "message"
git push
如果初次添加则需要:
git push --set-upstream origin master
如果遇到如下问题:
![rejected]master -> master (non-fast-forward)  
error: failed to push some refs to git@github.com:yangchao0718/cocos2d.git
hint: Updates were rejected because the tip of your current branch is behin 
出现错误的主要原因是github中的README.md文件不在本地代码目录中
可以通过如下命令进行代码合并[注:pull=fetch+merge]
git pull --rebase origin master
执行上面代码后可以看到本地代码库中多了README.md文件
此时再执行语句 git push -u origin master即可完成代码上传到github.com

No comments:

Post a Comment