参考博客:http://www.cocoachina.com/ios/20161009/17698.html
二, 开始建立本地库,在终端继续输入
1.cd到目标文件夹。
2.git init(在本机上想要创建一个新的git仓库)
3.git add -A (这里的-A是指将目标文件的所有文件都添加到git中,若不需要添加所有文件,可将-A换成具体的文件名)
4.git remote add origin xxxxxxxxx xxxxxx就是你仓库的地址
5.git commit -m “firstCommit” ("firstCommit" 也可以改成其他的说明性的文字,最终会显示在 github 界面 文件名的后边)
如下图红框所示
在第一次上传代码时 出现了以下情况:
*** Please tell me who you are.
Run
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
to set your account's default identity.
Omit --global to set the identity only in this repository.
fatal: unable to auto-detect email address (got 'crystal@crystal-Inspiron-5425.(none)')
这里是让你输入全局项目的 user.email 和 user.name.当然每个项目也可以设置局部的 user.email 和 user.name. 由于初步使用,故根据提示输入以下指令
git config --global user.email "*****@gmail.com"
git config --global user.name "crystal"
6.git pull --rebase origin master 更新远程更新到本地
推送本地更新到远程:
出现错误:
fatal: Couldn't find remote ref master
新建的项目,pull的时候出现这错误,其实说白了就是这个项目还没有文件,空的,直接把本地修改的上传就可以了,不需要拉了
即新建的项目可跳过此项。
7.git push origin master(git push -u origin master) 将本地repo于远程的origin的repo合并,第一次用-u,系统要求输入账号密码
此时会出现
Username for 'https://github.com':
Password for 'https://crystal30@github.com':
根据提示输入github帐号密码即可
出现错误:
"提示:更新被拒绝,因为您当前分支的最新提交落后于其对应的远程分支。"
git remote add origin https://github.com/username/Hello-World.git
$git fetch origin //获取远程更新
$git merge origin/master //把更新的内容合并到本地分支
8.git pull
出现问题:
根据提示,重新为git pull 添加跟踪分支
git branch –set-upstream-to=origin/master master
9.去Github上面检查代码,已经上传成功。
三,使用过程中可能出现的问题
1.我们想要在github上面删除某个文件夹,但又不想在本地删除。然而,github界面上只能删除文件而不能删除文件夹(下图为一个文件)
所以只能用指令来操作
步骤:(以删除.idea文件夹为例)
git rm -r --cached .idea #--cached不会把本地的.idea删除
git commit -m 'delete .idea dir'
git push -u origin master