Github是全球最大的代码托管网站,主要是借助Git来进行版本控制的。任何开源软件都可以免费的将代码提交到GitHub上,以零成本的代价进行代码的托管,GitHub的官网地址是https://github.com
一、创建一个github的仓库
1、首先创建一个github的账号
2、然后创建一个新的免费仓库
然后“Start a project”
在这里版本的命名Repository name
为test(这个命名可以随便来,后面的我都用coolweather,因为我部署的就是这个项目的代码)
选择一个Android项目类型的.gitignore文件,并使用Apache License 2.0来作为项目的开源协议。
然后点击Create repository
按钮,那么coolweather版本库就创建完成了,如图所示(下图是我部署后的最后结果)
https://github.com/chencong-plan/coolweather
二、利用Android studio创建coolweather项目
三、下载安装Git工具
https://git-for-windows.github.io/ 这是官网下载
安装好后选择使用 Git Brash
命令行来操作(这样有利于了解使用git的核心吧)
四、部署代码
1、查看自己用户名和邮箱,如果没有的话,添加就行
命令:$ git config --global user.name
和 $ git config --global user.email
,下面是结果:
chencong@▒´▒ MINGW64 /
$ git config --global user.name
chencong
chencong@▒´▒ MINGW64 /
$ git config --global user.email
1042738887@qq.com
2、进入CoolWeather的工程目录下
chencong@▒´▒ MINGW64 /
$ cd g:
chencong@▒´▒ MINGW64 /g
$ cd Android_application/201607/CoolWeather
chencong@▒´▒ MINGW64 /g/Android_application/201607/CoolWeather (master)
3、将远程版本克隆到本地
接着输入 https://github.com/chencong-plan/coolweather.git,将这个远程版本库克隆到本地,
$ git clone https://github.com/chencong-plan/coolweather.git
Cloning into 'coolweather'...
remote:Counting objects: 14,done.
remote:Compressing objects:100% <13/13>,done.
remote:Total 14 5>,reused 0 0>
Unpacking objects: 100% <14/14>,done.
Checking connectivity....done
看到上面所示,就说明已经克隆成功。
可以用命令ls -al
查看
上面是我克隆成功并且部署了的代码,这一步重点是克隆
4、现在我们需要将这个目录中的所有文件全部复制到上一层目录中,这样就能够将所有的CoolWeather工程目录添加到版本控制中。
注:.git是一个隐藏目录,在复制的时候不要遗忘了,可以先显示所有隐藏文件,当.git显示出来后在复制
复制完后最终的CoolWeather工程的目录结构如下:
chencong@▒´▒ MINGW64 /g/Android_application/201607/CoolWeather (master)
$ ls -al
total 61
drwxr-xr-x 1 chencong 197608 0 7月 12 19:25 ./
drwxr-xr-x 1 chencong 197608 0 7月 12 18:54 ../
drwxr-xr-x 1 chencong 197608 0 7月 12 19:38 .git/
-rw-r--r-- 1 chencong 197608 505 7月 12 19:19 .gitignore
drwxr-xr-x 1 chencong 197608 0 7月 12 18:55 .gradle/
drwxr-xr-x 1 chencong 197608 0 7月 12 18:56 .idea/
drwxr-xr-x 1 chencong 197608 0 7月 12 18:56 app/
drwxr-xr-x 1 chencong 197608 0 7月 12 18:55 build/
-rw-r--r-- 1 chencong 197608 521 7月 12 18:54 build.gradle
drwxr-xr-x 1 chencong 197608 0 7月 12 19:19 coolweather/
-rw-r--r-- 1 chencong 197608 942 7月 12 18:55 CoolWeather.iml
drwxr-xr-x 1 chencong 197608 0 7月 12 18:54 gradle/
-rw-r--r-- 1 chencong 197608 872 7月 12 18:54 gradle.properties
-rwxr-xr-x 1 chencong 197608 4971 7月 12 18:54 gradlew*
-rw-r--r-- 1 chencong 197608 2404 7月 12 18:54 gradlew.bat
-rw-r--r-- 1 chencong 197608 11558 7月 12 19:19 LICENSE
-rw-r--r-- 1 chencong 197608 450 7月 12 18:54 local.properties
-rw-r--r-- 1 chencong 197608 13 7月 12 19:19 README.md
-rw-r--r-- 1 chencong 197608 16 7月 12 18:54 settings.gradle
5、将CoolWeather项目中现有的文件提交到GitHub上。
①先将所有文件添加到版本控制中;
注意:这里有个”.”不要忘记了
$ git add .
结果如下所示:
chencong@▒´▒ MINGW64 /g/Android_application/201607/CoolWeather (master)
$ git add .
warning: LF will be replaced by CRLF in .idea/compiler.xml.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in .idea/encodings.xml.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in .idea/gradle.xml.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in .idea/misc.xml.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in .idea/modules.xml.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in .idea/runConfigurations.xml.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in gradle/wrapper/gradle-wrapper.properties .
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in gradlew.
The file will have its original line endings in your working directory.
② 本地执行提交操作:
$ git commit -m "First commit."
执行结果如下
chencong@▒´▒ MINGW64 /g/Android_application/201607/CoolWeather (master)
$ git commit -m "First commit."
[master eebe3d0] First commit.
warning: LF will be replaced by CRLF in .idea/compiler.xml.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in .idea/encodings.xml.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in .idea/gradle.xml.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in .idea/misc.xml.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in .idea/modules.xml.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in .idea/runConfigurations.xml.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in gradle/wrapper/gradle-wrapper.properties .
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in gradlew.
The file will have its original line endings in your working directory.
41 files changed, 656 insertions(+)
create mode 100644 .idea/.name
create mode 100644 .idea/compiler.xml
create mode 100644 .idea/copyright/profiles_settings.xml
create mode 100644 .idea/encodings.xml
create mode 100644 .idea/gradle.xml
create mode 100644 .idea/libraries/animated_vector_drawable_23_4_0.xml
create mode 100644 .idea/libraries/appcompat_v7_23_4_0.xml
create mode 100644 .idea/libraries/hamcrest_core_1_3.xml
create mode 100644 .idea/libraries/junit_4_12.xml
create mode 100644 .idea/libraries/support_annotations_23_4_0.xml
create mode 100644 .idea/libraries/support_v4_23_4_0.xml
create mode 100644 .idea/libraries/support_vector_drawable_23_4_0.xml
create mode 100644 .idea/misc.xml
create mode 100644 .idea/modules.xml
create mode 100644 .idea/runConfigurations.xml
create mode 100644 app/.gitignore
create mode 100644 app/build.gradle
create mode 100644 app/proguard-rules.pro
create mode 100644 app/src/androidTest/java/com/example/chencong/coolweather/Ap plicationTest.java
create mode 100644 app/src/main/AndroidManifest.xml
create mode 100644 app/src/main/java/com/example/chencong/coolweather/MainActiv ity.java
create mode 100644 app/src/main/res/layout/activity_main.xml
create mode 100644 app/src/main/res/mipmap-hdpi/ic_launcher.png
create mode 100644 app/src/main/res/mipmap-mdpi/ic_launcher.png
create mode 100644 app/src/main/res/mipmap-xhdpi/ic_launcher.png
create mode 100644 app/src/main/res/mipmap-xxhdpi/ic_launcher.png
create mode 100644 app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
create mode 100644 app/src/main/res/values-w820dp/dimens.xml
create mode 100644 app/src/main/res/values/colors.xml
create mode 100644 app/src/main/res/values/dimens.xml
create mode 100644 app/src/main/res/values/strings.xml
create mode 100644 app/src/main/res/values/styles.xml
create mode 100644 app/src/test/java/com/example/chencong/coolweather/ExampleUn itTest.java
create mode 100644 build.gradle
create mode 160000 coolweather
create mode 100644 gradle.properties
create mode 100644 gradle/wrapper/gradle-wrapper.jar
create mode 100644 gradle/wrapper/gradle-wrapper.properties
create mode 100644 gradlew
create mode 100644 gradlew.bat
create mode 100644 settings.gradle
③ 将提交的内容同步到GitHub
$ git push origin master
运行结果如下:
chencong@▒´▒ MINGW64 /g/Android_application/201607/CoolWeather (master)
$ git push origin master
Counting objects: 76, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (47/47), done.
Writing objects: 100% (76/76), 87.83 KiB | 0 bytes/s, done.
Total 76 (delta 2), reused 0 (delta 0)
To https://github.com/chencong-plan/coolweather.git
f54379f..eebe3d0 master -> master
注意:最后一步的时候GitHub要求输入用户名和密码来进行身份验证,这里输入的是注册时填入的用户名和密码
这样我们就已经完成了同步,最后我们来到GitHub里面,刷新一下我们创建的主页,就会看到提交的文件都已经存在了。如下所示
Create by chencong3139
2016年7月12日21:20:06
我挥舞着键盘和本子,
发誓要把世界写个明明白白!
《第一行代码》郭霖