利用命令行將Android studio中項目部署到github上

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項目

這裏寫圖片描述
在這裏選擇的版本爲4.1 API 15
這裏寫圖片描述
然後後面一直下去。

三、下載安裝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 <delta 5>,reused 0 <delta 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 712 19:25 ./
drwxr-xr-x 1 chencong 197608     0 712 18:54 ../
drwxr-xr-x 1 chencong 197608     0 712 19:38 .git/
-rw-r--r-- 1 chencong 197608   505 712 19:19 .gitignore
drwxr-xr-x 1 chencong 197608     0 712 18:55 .gradle/
drwxr-xr-x 1 chencong 197608     0 712 18:56 .idea/
drwxr-xr-x 1 chencong 197608     0 712 18:56 app/
drwxr-xr-x 1 chencong 197608     0 712 18:55 build/
-rw-r--r-- 1 chencong 197608   521 712 18:54 build.gradle
drwxr-xr-x 1 chencong 197608     0 712 19:19 coolweather/
-rw-r--r-- 1 chencong 197608   942 712 18:55 CoolWeather.iml
drwxr-xr-x 1 chencong 197608     0 712 18:54 gradle/
-rw-r--r-- 1 chencong 197608   872 712 18:54 gradle.properties
-rwxr-xr-x 1 chencong 197608  4971 712 18:54 gradlew*
-rw-r--r-- 1 chencong 197608  2404 712 18:54 gradlew.bat
-rw-r--r-- 1 chencong 197608 11558 712 19:19 LICENSE
-rw-r--r-- 1 chencong 197608   450 712 18:54 local.properties
-rw-r--r-- 1 chencong 197608    13 712 19:19 README.md
-rw-r--r-- 1 chencong 197608    16 712 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
我揮舞着鍵盤和本子,
發誓要把世界寫個明明白白!
        《第一行代碼》郭霖
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章