1.首先把Git安装好,然后进入到要本分的代码根目录下,最好把一个工程单独放到一个目录下
2.在跟目录下执行
- git init
- git add .
- git commit -m " commit log here"
3.第2步执行完是说把当前目录下的代码添加到本地的库中了,然后就是要将本地库同步到github上,在这个之前需要做一些配置
4.https://help.github.com/articles/generating-ssh-keys,这个就是在配置sshkey(第二次貌似不用再配置了)
5.第4步完成后就可以同步代码了,不过需要先登录github上先创建一个库,就是我们代码要同步到的库
6.然后执行
git remote add origin https://github.com/lycasa/weibo4android.git
git push -u origin master
需要输入登录github的用户名和密码
7.
测试github
ssh -T git@github.com
# Attempts to ssh to github
You may see this warning:
# The authenticity of host 'github.com (207.97.227.239)' can't be established. # RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48. # Are you sure you want to continue connecting (yes/no)?
git remote add origin https://github.com/lycasa/weibo4android.git
7.
测试github
ssh -T git@github.com
# Attempts to ssh to github
You may see this warning:
Don't worry, this is supposed to happen. Verify that the fingerprint matches the one here and type "yes".
8.第6步Push的时候可能会出现问题
当要push代码到git时,出现提示:
error:failed to push some refs to ...
Dealing with “non-fast-forward” errorsFrom time to time you may encounter this error while pushing:
解决方法:
- $ git config branch.master.remote origin
- $ git config branch.master.merge refs/heads/master
3.git pull(这个地方会弹出来个nano,恶心死了,你别管它,都是通过ctrl+?来执行命令的,直接用退出的那个,好像是ctrl+x,
还是ctrl+c,然后按一下n键(像是说不保存))
4.然后再执行第6步的Push操作
9.最好是把要上传的代码放到一个文件夹下,比如/environment/github/a1/a2/上传的代码 一般a1.a2可以命名相同
10.在以上过程如果出现多次错误,可以把库给删除了,重新在本地找个目录或者重新命名文件夹再上传,网站删除库在setting按钮下边
11.向github提交代码更新
git add .
git commit -m "说明"
git push -u origin master然后输入github上注册的用户名和密码即可