GitHub快速入門

 

    閒話少說,首先去github的網站註冊一個帳號(https://github.com),並且創建一個倉庫。這個就是git中的中央倉庫了,我們在本地的代碼可以提交到這裏。看看下面的一張圖你會更加明白些:



 

   一, 安裝githttps://code.google.com/p/msysgit/downloads/list?can=3)。

     安裝好以後啓動Git Bash。

     輸入:

 

cd ~/.ssh
ls
# Lists the files in your .ssh directory

    注:#開頭的都是註釋 不用輸入的。

 

    看看有沒有id_dsa.pub和id_rsa.pub兩個文件(剛安裝一般都沒了。。。。)

    生成一個新的SSHkey:

   運行以下:

ssh-keygen -t rsa -C "[email protected]"
# Creates a new ssh key, using the provided email as a label
# Generating public/private rsa key pair.
# Enter file in which to save the key (/c/Users/you/.ssh/id_rsa): [Press enter]
ssh-add id_rsa

    然後就會提示你輸入密碼:

Enter passphrase (empty for no passphrase): [Type a passphrase]
Enter same passphrase again: [Type passphrase again]

 然後就會出現下面類似的信息:

 

 

Your identification has been saved in /c/Users/you/.ssh/id_rsa.
# Your public key has been saved in /c/Users/you/.ssh/id_rsa.pub.
# The key fingerprint is:
# 01:0f:f4:3b:ca:85:d6:17:a1:7d:f0:68:9d:f0:a2:db [email protected]

 

 

 

  二, 將你的SSH Key添加到GitHub

   複製SSH Key:

 

clip < ~/.ssh/id_rsa.pub

   1, 登錄你的GitHub,點擊右上角的“Account Settings”

 

    2, 點擊右邊“SSH Keys”

    3,點擊“Add SSH Key”

    4,將剛纔複製的SSH Key粘貼到“Key”裏面

    5,點擊下面的“Add key”

 

   好了以上的準備工作做好了。

 

  三,本地修改項目後提交到GitHub

mkdir gitrepo  # 創建項目目錄 

cd gitrepo  # 進入到項目目錄 

git init #初始化 git 倉庫。此命令會在當前目錄新建一個.git 目錄,用於存儲 git 倉庫的相關信息

git clone <url> #從GitHub上克隆一個項目到本地,url是項目在github上的路徑。類似這樣https://github.com/username/repo.git

#做一些修改。如添加一個文件。

git add * #將修改的內容添加到index緩衝區。

git commit -m "一些提交內容的說明" #提交改動到HEAD

git remote -v #查看現有的遠程服務器

git remote add <name> <url> #添加一個遠程的服務器

一般你可以這樣寫:git remote add origin [email protected]:USER/REPO.git

git push #提交更改到GitHub

 

OK.你進行的還順利嗎?哈哈,快去gitHub看看有沒有添加了一個文件吧

想要了解更多可以看看這個:

http://stackoverflow.com/questions/20871549/error-when-push-commits-with-github-fatal-could-not-read-username

https://help.github.com/articles/generating-ssh-keys

http://rogerdudler.github.io/git-guide/index.zh.html 

 

下面是網友們整理的:

查看提交日誌

git log  # 查看提交信息 
git log  --pretty=oneline  # 以整潔的單行形式顯示提交信息

Git 分支

git branch  # 查看分支 
git branch  6.x- 1.x  # 添加分支 6.x-1.x 
git branch checkout master  # 切換到主分支 
git branch  -d  6.x- 1.x  # 刪除分支 6.x-1.x 
git push origin :branchname  # 刪除遠端分支

Git 標籤

git tag  # 查看分支 
git tag  6.x- 1.0  # 添加標籤 6.x-1.0 
git show  6.x- 1.0  # 查看標籤 6.x-1.0 的信息 
git tag  -a  6.x- 1.0 965e066  # 爲之前提交的信息記錄 965e066 加上標籤 
git push  --tags  # 提交時帶上標籤信息 
git push origin : /refs /tags /tagname  # 刪除遠端標籤

從 git 倉庫中導出項目

git archive  --format  tar  --output  /path /to /file.tar master  # 將 master 以 tar 格式打包到指定文件

使用 Git 的一些基本守則: 當要commit/提交patch時:

  • 使用 git diff --check 檢查行尾有沒有多餘的空白
  • 每個 commit 只改一件事情。如果一個文檔有多個變更,使用 git add --patch 只選擇文檔中的部分變更進入 stage
  • 寫清楚 commit message
    Eclipse中使用egit 出現The current branch is not configured for pull錯誤的解決辦法
    stackoverflow有很好的解決方法,地址如下:
    http://stackoverflow.com/questions/8820668/the-current-branch-is-not-configured-for-pull-no-value-for-key-branch-master-mer


    用的是隻有被投4票的一個答案,完美的解決了我的問題:
    To fix this problem in Eclipse, open the Windows menu and select Show View / Other / Git Repositories.

    From the Git Repositories tab:

    expand your local repository
    right click on Remote
    click on Create Remote...
    Remote name = origin
    next to IRI press the Change button
    CTRL+SPACE on URI
    select the remote location
    press Finish
    press Save and Push
    Again, from the Git Repositories tab:

    right click on origin
    select Configure Fetch...
    on Ref mapping press the Edit (Advanced)...
    press Add All Branches Spec
    select the Force Update checkbox
    press Finish
    Again, from the Git Repositories tab:

    right click on your local repository
    select Properties
    press New Entry...
    enter the following two keys:
    (1)

    Key = branch.master.remote
    Value = origin
    (2)

    Key = branch.master.merge
    Value = refs/heads/master
     
     
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章