Contents

github上传代码的方法

Contents

今天研究了下github上传代码,果然是比较麻烦啊。把心得写在这里备忘。

首先在github上创建一个新的repositories,如图步骤

http://www.ithome.me/wp-content/uploads/2013/12/1.png

之后填入你的项目名称,描述,后面还有一个Initialize this repository with a README,建议够选上,因为这个东西是必备的,然后是选择你项目的程序语言,发布许可类型之类的,可以不选

http://www.ithome.me/wp-content/uploads/2013/12/2-300x176.png

点击Great repository按钮完成创建,这样我们就有一个资源库了,接下来是上传代码进入这个库。

http://windows.github.com/ 下载git工具,自动安装完成后有两个工具,GitHub和Git Shell,首先我们运行GitHub并且输入帐号密码,选择好你自定义的git路径,完成配置,然后回到网页的github帐号管理,

点击Account Settings-SSH Keys,此时应该会有一条自动加入的key等待你验证,点击approbate批准即可。

接下来运行刚才安装的Git Shell进入命令行,输入命令

[code lang=“shell”]ssh -T git@github.com [/code]

如果正确则会出现

Warning: Permanently added 'github.com,207.97.227.239' (RSA) to the list of known hosts.
Hi xxoo! You've successfully authenticated, but GitHub does not provide shell access.

如果出现其他信息,请检查网络原因,比如墙什么的。

从网页上得到你的项目地址:

http://www.ithome.me/wp-content/uploads/2013/12/3.png

接着继续在Git Shell输入命令: [code lang=“shell”]git clone https://github.com/cikichen/Plane-Fight.git[/code]

成功信息:

Cloning into 'Plane-Fight'...
remote: Counting objects: 4, done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 4 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (4/4), done.
Checking connectivity... done

这样你的项目就被拷贝到本地了,你会得到一个Plane-Fight(你的项目名)文件夹,然后把你的代码放入到这个文件夹中,cd进入文件夹.依次输入下面的命令 [code lang=“shell”] git add . git commit -m ‘first_commit’ git remote add origin https://github.com/cikichen/Plane-Fight.git git push origin master[/code]

如果输入git remote add origin https://github.com/cikichen/Plane-Fight.git 后提示

fatal: remote origin already exists.

那么输入命令: [code lang=“shell”]git remote rm origin[/code] 如果继续提示:

error: Could not remove config section 'remote.origin'

网上提供的方法是: C:\Users<your computer name>\AppData\Local\GitHub\PortableGit_ca477551eeb4aea0e4ae9fcd3358bd96720bb5c8\etc找到一个gitconfig,把里面的[remote “origin”]删掉就好了,接着再运行以上命令。

如果从头开始的步骤都和我一样,那么此时再次执行git remote rm origin应该就会成功了。

以上! 如果有疑问,欢迎留言。