首頁 > 軟體

上傳專案到GitHub,同步遠端Github倉庫

2020-06-16 17:56:25

最近在寫一個簡單的Android專案,不過由於人員管理上鬆散,所以決定把程式碼提交至GitHub,提前感受一下一直很火的GitHub。

歷程簡述:

1、本來想偷懶,看看有沒有類似subversion,簡單操作的團隊開源工具,不過之前是在Javaweb方向上使用,在移動開發上當然用適合的工具了,於是捨棄之

2、再一想,有莫有eclipse的外掛,整合上傳,下載github上的原始碼呢?參考(使用GitHub管理Eclipse分散式專案開發 http://www.linuxidc.com/Linux/2015-08/120989.htm),但是說的不是很詳細,因為我的eclipse是最新google公司的版本,安上外掛會報錯,而且啟動介面也會有變化,搗鼓了2個小時,但是仍然沒有頭緒,又捨棄之。

3、最後,我安定思痛,想想我想要的流程是什麼?

上傳原生代碼->github網站

團隊其他人從上面拷貝下來

改完之後再提交上去

於是google之,

再參考下面這幾篇文章

在GitHub上分享和展示你的程式碼  http://www.linuxidc.com/Linux/2015-08/120997.htm

Git/Github使用方法筆記 http://www.linuxidc.com/Linux/2015-08/120993.htm

下面的程式碼是記錄記錄而已,有興趣的可以看一下,時間比較倉促,還望多多夠溝通,一起在github上關注、學習大牛們!

Welcome to Git (version 1.8.3-preview20130601)


Run 'git help git' to display the help index.
Run 'git help <command>' to display help for specific commands.

Administrator@VAIO-11061700 /d/GitHub/RescueApp
$ git config --global user.name "jptiancai"

Administrator@VAIO-11061700 /d/GitHub/RescueApp
$ git config --global user.email mail_jzy@163.com

Administrator@VAIO-11061700 /d/GitHub/RescueApp
$ ssh-keygen -C 'mail_jzy@163.com' -t rsa

Administrator@VAIO-11061700 /d/GitHub/RescueApp
$ ssh-keygen -C 'mail_jzy@163.com' -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Documents and Settings/Administrator/.ss
h/id_rsa):
/c/Documents and Settings/Administrator/.ssh/id_rsa already exists.
Overwrite (y/n)? y
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Documents and Settings/Administrator/.s
sh/id_rsa.
Your public key has been saved in /c/Documents and Settings/Administrator/.ssh/i
d_rsa.pub.
The key fingerprint is:
9f:be:0c:2e:de:a5:5f:2b:86:3e:73:1d:33:71:60:ab mail_jzy@163.com

Administrator@VAIO-11061700 /d/GitHub/RescueApp
$ git init
Initialized empty Git repository in D:/GitHub/RescueApp/.git/

Administrator@VAIO-11061700 /d/GitHub/RescueApp (master)
$ git add .
warning: LF will be replaced by CRLF in AndroidManifest.xml.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in gen/com/yonvoo/main/BuildConfig.java.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in proguard-project.txt.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in project.properties.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in res/values-v11/styles.xml.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in res/values-v14/styles.xml.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in res/values/strings.xml.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in res/values/styles.xml.
The file will have its original line endings in your working directory.

Administrator@VAIO-11061700 /d/GitHub/RescueApp (master)
$ git remote add origin git@github.com:jptiancai/RescueApp.git

Administrator@VAIO-11061700 /d/GitHub/RescueApp (master)
$ git push origin master
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

Administrator@VAIO-11061700 /d/GitHub/RescueApp (master)
$ git push origin master
The authenticity of host 'github.com (204.232.175.90)' 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)? y
Please type 'yes' or 'no': yes
Warning: Permanently added 'github.com,204.232.175.90' (RSA) to the list of know
n hosts.
error: src refspec master does not match any.
error: failed to push some refs to 'git@github.com:jptiancai/RescueApp.git'

Administrator@VAIO-11061700 /d/GitHub/RescueApp (master)
$ git push origin master
error: src refspec master does not match any.
error: failed to push some refs to 'git@github.com:jptiancai/RescueApp.git'

Administrator@VAIO-11061700 /d/GitHub/RescueApp (master)
$ git commit -m 'initial commit'
[master (root-commit) 926da3f] initial commit
warning: LF will be replaced by CRLF in AndroidManifest.xml.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in gen/com/yonvoo/main/BuildConfig.java.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in proguard-project.txt.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in project.properties.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in res/values-v11/styles.xml.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in res/values-v14/styles.xml.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in res/values/strings.xml.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in res/values/styles.xml.
The file will have its original line endings in your working directory.
 74 files changed, 1548 insertions(+)
 create mode 100644 .gitattributes
 create mode 100644 .gitignore
 create mode 100644 AndroidManifest.xml
 create mode 100644 gen/com/yonvoo/main/BuildConfig.java
 create mode 100644 gen/com/yonvoo/main/R.java
 create mode 100644 ic_launcher-web.png
 create mode 100644 libs/android-support-v4.jar
 create mode 100644 proguard-project.txt
 create mode 100644 project.properties
 create mode 100644 res/drawable-hdpi/app_logo.png
 create mode 100644 res/drawable-hdpi/bg.png
 create mode 100644 res/drawable-hdpi/butten_pressed.png
 create mode 100644 res/drawable-hdpi/dark_dot.png
 create mode 100644 res/drawable-hdpi/guide_350_01.jpg
 create mode 100644 res/drawable-hdpi/guide_350_02.jpg
 create mode 100644 res/drawable-hdpi/guide_350_03.jpg
 create mode 100644 res/drawable-hdpi/guide_350_04.jpg
 create mode 100644 res/drawable-hdpi/ic_launcher.png
 create mode 100644 res/drawable-hdpi/item_bg.png
 create mode 100644 res/drawable-hdpi/photo8.png
 create mode 100644 res/drawable-hdpi/richangyiwai.png
 create mode 100644 res/drawable-hdpi/settings.png
 create mode 100644 res/drawable-hdpi/welcome.png
 create mode 100644 res/drawable-hdpi/welcome_android.jpg
 create mode 100644 res/drawable-hdpi/white_dot.png
 create mode 100644 res/drawable-hdpi/yundongzijiu.png
 create mode 100644 res/drawable-hdpi/ziranzaihai.png
 create mode 100644 res/drawable-ldpi/butten_pressed.png
 create mode 100644 res/drawable-ldpi/butten_unpress.png
 create mode 100644 res/drawable-ldpi/dark_dot.png
 create mode 100644 res/drawable-ldpi/guide_350_01.jpg
 create mode 100644 res/drawable-ldpi/guide_350_02.jpg
 create mode 100644 res/drawable-ldpi/guide_350_03.jpg
 create mode 100644 res/drawable-ldpi/guide_350_04.jpg
 create mode 100644 res/drawable-ldpi/ic_launcher.png
 create mode 100644 res/drawable-ldpi/logo.png
 create mode 100644 res/drawable-ldpi/welcome_android.jpg
 create mode 100644 res/drawable-ldpi/white_dot.png
 create mode 100644 res/drawable-mdpi/ic_launcher.png
 create mode 100644 res/drawable-xhdpi/ic_launcher.png
 create mode 100644 res/drawable/dot.xml
 create mode 100644 res/drawable/whats_new_start_btn.xml
 create mode 100644 res/layout/detail.xml
 create mode 100644 res/layout/griditem.xml
 create mode 100644 res/layout/guide.xml
 create mode 100644 res/layout/listview_item.xml
 create mode 100644 res/layout/main.xml
 create mode 100644 res/layout/splash.xml
 create mode 100644 res/layout/test.xml
 create mode 100644 res/layout/what_new_four.xml
 create mode 100644 res/layout/what_new_one.xml
 create mode 100644 res/layout/what_new_three.xml
 create mode 100644 res/layout/what_new_two.xml
 create mode 100644 res/menu/activity_main.xml
 create mode 100644 res/values-v11/styles.xml
 create mode 100644 res/values-v14/styles.xml
 create mode 100644 res/values/strings.xml
 create mode 100644 res/values/styles.xml
 create mode 100644 src/com/yonvoo/activity/DetailActivity.java
 create mode 100644 src/com/yonvoo/activity/GuideActivity.java
 create mode 100644 src/com/yonvoo/activity/MainActivity.java
 create mode 100644 src/com/yonvoo/activity/SecCategoryActivity.java
 create mode 100644 src/com/yonvoo/activity/SplashActivity.java
 create mode 100644 src/com/yonvoo/adapter/GridViewAdapter.java
 create mode 100644 src/com/yonvoo/adapter/ListViewAdapter.java
 create mode 100644 src/com/yonvoo/adapter/ViewPagerAdapter.java
 create mode 100644 src/com/yonvoo/domain/Category.java
 create mode 100644 src/com/yonvoo/domain/Detail.java
 create mode 100644 src/com/yonvoo/domain/SecCategory.java
 create mode 100644 src/com/yonvoo/service/CategoryService.java
 create mode 100644 src/com/yonvoo/service/DBHelper.java
 create mode 100644 src/com/yonvoo/service/DetailService.java
 create mode 100644 src/com/yonvoo/service/SecCategoryService.java
 create mode 100644 src/com/yonvoo/test/DBTest.java

Administrator@VAIO-11061700 /d/GitHub/RescueApp (master)
$ git push origin master
To git@github.com:jptiancai/RescueApp.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'git@github.com:jptiancai/RescueApp.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first merge the remote changes (e.g.,
hint: 'git pull') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

Administrator@VAIO-11061700 /d/GitHub/RescueApp (master)
$ git push -f
warning: push.default is unset; its implicit value is changing in
Git 2.0 from 'matching' to 'simple'. To squelch this message
and maintain the current behavior after the default changes, use:

  git config --global push.default matching

To squelch this message and adopt the new behavior now, use:

  git config --global push.default simple

See 'git help config' and search for 'push.default' for further information.
(the 'simple' mode was introduced in Git 1.7.11. Use the similar mode
'current' instead of 'simple' if you sometimes use older versions of Git)

Counting objects: 92, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (81/81), done.
Writing objects: 100% (92/92), 2.20 MiB | 966.00 KiB/s, done.
Total 92 (delta 12), reused 0 (delta 0)
To git@github.com:jptiancai/RescueApp.git
 + be58463...926da3f master -> master (forced update)

Administrator@VAIO-11061700 /d/GitHub/RescueApp (master)
$

---------------------------------------------------後續更新--------------------------------------------------

時隔多日,再次用到git這個神級的版本管理工具的時候,上面的程式碼依然有用,在這裡稍微總結一下,方便以後檢視:

建立個人專案到github上或者fork別人的專案

 

      1. 設定使用者名稱、密碼、私鑰--->和github取得連線,如需要設定代理上網,請看這篇:在公司的區域網使用git或github 設定代理[1]
      2. 新增本地檔案到github程式碼庫中---> inti,add,remote add, commit,push,遇到master整合到master的時候,可以用 -f,強制merge
      3. git clone github地址,可參照下圖直接複製貼上。

 

      • GitHub Guides[2]:目前教學文章較少,僅僅9篇,但是篇篇都很經典,從HelloWorld開始看,你一定會有收穫。
      • Git官網[3]:網站十分友好,提供了線上TryGit學習方式,文件,視訊,軟體,一應俱全。
      • Git cheatsheet[4]:裡面有大部分的命令,很實用!

提交你自己的程式碼,參考Pushing to a remote[1]

fork你喜歡的庫

git branch new_branch
git checkout new_branch
一系列操作(git add......)
git push origin new_branch

---------------- 

之後重新整理官網會有所顯示,提交上去,等待使用者稽核通過

提交自己的程式碼,同步最新的程式碼,參考[2],[3]

merge到自己專案的master上,提交後就看原作者的稽核了
 git checkout master--->以master的身份執行
 git merge new_branch
 git diff new_branch master
 git status

情景:已經從原始專案(orgin)在頁面上fork一個自己的專案主頁(master),本地上也有一個工作版本(local,雖然在控制台上看到的是master,但是應該這樣理解).最近看到origin專案更新的好多東西,首先是更新 

  • git fetch xx(origin專案的git地址,這個可以在頁面copy):bash返回資訊  * branch  HEAD  -> FETCH_HEAD
  • git merge HEAD FETCH_HEAD:按照提示,本地倉庫(local)和原始專案(origin)同步資訊
  • git push:本地專案(local)提交到自己的專案主頁(master).

參考文章

[1] Pushing to a remote
[2]. 如何在GitHub上傳專案貢獻程式碼

GitHub 教學系列文章: 

通過GitHub建立個人技術部落格圖文詳解  http://www.linuxidc.com/Linux/2015-02/114121.htm

GitHub 使用教學圖文詳解  http://www.linuxidc.com/Linux/2014-09/106230.htm 

Git 標籤管理詳解 http://www.linuxidc.com/Linux/2014-09/106231.htm 

Git 分支管理詳解 http://www.linuxidc.com/Linux/2014-09/106232.htm 

Git 遠端倉庫詳解 http://www.linuxidc.com/Linux/2014-09/106233.htm 

Git 本地倉庫(Repository)詳解 http://www.linuxidc.com/Linux/2014-09/106234.htm 

Git 伺服器搭建與用戶端安裝  http://www.linuxidc.com/Linux/2014-05/101830.htm 

Git 概述 http://www.linuxidc.com/Linux/2014-05/101829.htm 

分享實用的GitHub 使用教學 http://www.linuxidc.com/Linux/2014-04/100556.htm 


IT145.com E-mail:sddin#qq.com