github使用簡介

去年暑假接觸到的git,因爲以後不常常使用,漸漸變得陌生了,今日使用起來git感受仍是有點吃力,因此就總結下,以方便本身往後的查找,也方便別人學習。html

一、要想使用github,首先你要有一個github帳號,這樣的話,才能把本地的代碼上傳到github服務器java

二、創建本地的倉庫mysql

git init                           //創建本地倉庫
touch readme.txt                   //建立一個文件
git add -A                         //添加要提交的文件,-A參數是添加全部的
git commit -m "this is note"       //提交,引號中的是註釋

這樣一個本地倉庫就建立完畢。android

 

三、將本地的git倉庫與github關聯git

要想將本地的git與github關聯,首先要在本地建立key,而且把公鑰添加到github中github

生成key的命令,具體的效果見下圖sql

$ git config --global user.name zhanghuijun-alite
$ git config --global user.email "1483386979@qq.com"
$ ssh-keygen -t rsa -C "1483386979@qq.com"

在「C:\Users\Administrator\.ssh」下生成了兩個文件json

把公鑰文件用記事本打開,粘貼到github中的相應位置,到此爲止,下面就能夠愉快的上傳代碼了服務器

使用的命令以下:eclipse

$ git remote add origin git@github.com:zhanghuijun0/demo-for-android.git    #創建本地與遠程關聯
$ git pull origin master                                   #更新代碼到本地,若是省略這一步,會報錯
$ git push -u origin master                                #提交代碼到github

 

 四、平時必用的git命令(因爲這個是一我的操做,沒有涉及到分支,及其其餘狀況)

$ git add -A
$ git commit -m "test1"
$ git pull origin master
$ git push -u origin master

五、下面是一個簡單是示例, 首先在github上邊有一個倉庫,在本機新建一個倉庫,建立了一個readme.txt文件,把readme.txt文件上傳到github

上傳前github的截圖:

上傳後github的截圖:

 操做步驟:

Administrator@lihuasheng MINGW64 ~/Desktop/demo
$ git init
Initialized empty Git repository in C:/Users/Administrator/Desktop/demo/.git/

Administrator@lihuasheng MINGW64 ~/Desktop/demo (master)
$ touch readme.txt

Administrator@lihuasheng MINGW64 ~/Desktop/demo (master)
$ git add -A

Administrator@lihuasheng MINGW64 ~/Desktop/demo (master)
$ git commit -m "this is note"
[master (root-commit) 94d2d63] this is note
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 readme.txt

Administrator@lihuasheng MINGW64 ~/Desktop/demo (master)
$ git remote add origin git@github.com:zhanghuijun0/work.git

Administrator@lihuasheng MINGW64 ~/Desktop/demo (master)
$ git pull origin master
warning: no common commits
remote: Counting objects: 36, done.
remote: Total 36 (delta 0), reused 0 (delta 0), pack-reused 36
Unpacking objects: 100% (36/36), done.
From github.com:zhanghuijun0/work
 * branch            master     -> FETCH_HEAD
 * [new branch]      master     -> origin/master
Merge made by the 'recursive' strategy.
 .classpath                               |   9 ++
 .gitignore                               |   1 +
 .project                                 |  17 +++
 .settings/org.eclipse.jdt.core.prefs     |  11 ++
 lib/json.jar                             | Bin 0 -> 94360 bytes
 lib/jsoup-1.8.3.jar                      | Bin 0 -> 315321 bytes
 lib/mysql-connector-java-5.1.22-bin.jar  | Bin 0 -> 832960 bytes
 log2015-10-17.log                        |   9 ++
 log20151017.log                          |   1 +
 mysql.conf                               |   4 +
 src/com/zhj/tool/CommandHelper.java      |  46 ++++++
 src/com/zhj/tool/Connect.java            |  82 ++++++++++
 src/com/zhj/tool/CreateFolderHelper.java |  51 +++++++
 src/com/zhj/tool/FolderHelper.java       |  11 ++
 src/com/zhj/tool/JsonHelper.java         |  77 ++++++++++
 src/com/zhj/tool/RCommandHelper.java     |  42 +++++
 src/com/zhj/tool/Sleep.java              |  24 +++
 src/com/zhj/tool/SqlHelper.java          | 254 +++++++++++++++++++++++++++++++
 src/com/zhj/tool/TestTimer.java          |  46 ++++++
 src/com/zhj/tool/TimeHelper.java         | 128 ++++++++++++++++
 src/com/zhj/tool/WriteFileHelper.java    |  56 +++++++
 21 files changed, 869 insertions(+)
 create mode 100644 .classpath
 create mode 100644 .gitignore
 create mode 100644 .project
 create mode 100644 .settings/org.eclipse.jdt.core.prefs
 create mode 100644 lib/json.jar
 create mode 100644 lib/jsoup-1.8.3.jar
 create mode 100644 lib/mysql-connector-java-5.1.22-bin.jar
 create mode 100644 log2015-10-17.log
 create mode 100644 log20151017.log
 create mode 100644 mysql.conf
 create mode 100644 src/com/zhj/tool/CommandHelper.java
 create mode 100644 src/com/zhj/tool/Connect.java
 create mode 100644 src/com/zhj/tool/CreateFolderHelper.java
 create mode 100644 src/com/zhj/tool/FolderHelper.java
 create mode 100644 src/com/zhj/tool/JsonHelper.java
 create mode 100644 src/com/zhj/tool/RCommandHelper.java
 create mode 100644 src/com/zhj/tool/Sleep.java
 create mode 100644 src/com/zhj/tool/SqlHelper.java
 create mode 100644 src/com/zhj/tool/TestTimer.java
 create mode 100644 src/com/zhj/tool/TimeHelper.java
 create mode 100644 src/com/zhj/tool/WriteFileHelper.java

Administrator@lihuasheng MINGW64 ~/Desktop/demo (master)
$ git push -u origin master
Counting objects: 5, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (5/5), 514 bytes | 0 bytes/s, done.
Total 5 (delta 1), reused 0 (delta 0)
To git@github.com:zhanghuijun0/work.git
   a825e20..89dc692  master -> master
Branch master set up to track remote branch master from origin.

Administrator@lihuasheng MINGW64 ~/Desktop/demo (master)
$
View Code

 

 ==

相關鏈接:

Git教程 - 廖雪峯的官方網站 http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000

Git - Book http://git-scm.com/book/zh/v1

Git 使用方法 - zuibunan - 博客園 http://www.cnblogs.com/zuibunan/p/3843241.html

教你上傳本地代碼到github - 雨の殤的天空 - 博客頻道 - CSDN.NET http://blog.csdn.net/hanhailong726188/article/details/46738929

Git-Tutorial - GitBook https://www.gitbook.com/book/lvwzhen/git-tutorial/details

Git詳解之二 Git基礎 - OPEN 開發經驗庫 http://www.open-open.com/lib/view/open1328069733264.html

相關文章
相關標籤/搜索