您的位置:首页 > 编程语言

本地代码导入github仓库

2015-11-16 19:45 387 查看

问题背景

直接clone github代码库很容易,要是将本地已经存在的git仓库放到github上,这个又该如何操作呢?

这篇文章针对该问题进行说明。通过本文,您将知道如何将本地已经存在N多git记录的代码仓库 方便放到github上。

本地仓库

本地代码创建git库,容易,直接git init.

然后提交记录,这里我以 Ionic官网todo Project为例进行说明。

todo目录结构

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----       2015/11/16     11:42                .idea
d-----       2015/11/16     11:36                hooks
d-----       2015/11/16     11:47                platforms
d-----       2015/11/16     11:47                plugins
d-----       2015/11/16     11:47                resources
d-----       2015/11/16     11:36                scss
d-----       2015/11/16     16:48                www
-a----       2015/11/16     11:36             29 .bowerrc
-a----       2015/11/16     11:36            242 .editorconfig
-a----       2015/11/16     11:36            138 .gitignore
-a----       2015/11/16     11:36            118 bower.json
-a----       2015/11/16     11:47           2649 config.xml
-a----       2015/11/16     11:36           1385 gulpfile.js
-a----       2015/11/16     11:37             37 ionic.project
-a----       2015/11/16     11:47            609 package.json


其中 www/ 以及 .gitignore 是需要加入到git仓库中,其他暂时不用加入。

git如何忽略文件

这里插播题外话:git如何忽略文件 方法简单。

在.gitignore中加入不需要trace的文件夹或文件即可。

在本文实例中 .gitignore内容如下:

platforms/
plugins/
.bowerrc
.editorconfig
bower.json
config.xml
gulpfile.js
hooks/
ionic.project
package.json
resources/
scss/
.idea/


www 中添加必要文件以及git init, git add, git commit后。

查看此时的git log,如下:

PS E:\Web-DEV\Ionic\todo> git log
WARNING: terminal is not fully functional
commit 20a462e22c40915c8f12060df2456abf6338faec
Author: shrimpcolo <shrimpcolo@gmail.com>
Date:   Mon Nov 16 17:02:35 2015 +0800

init todo project


github仓库创建



Create repository



不要勾选README 直接Create repository



加入github仓库

直接按照上图中的cmd 提示:

git remote add origin https://github.com/tancolo/IonicDemo.git git push -u origin master


在本地仓库目录cmd line中分别输入上述命令。

其中需要输入git用户名和密码。



成功完成!

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息