其實,好幾個月前,就已經安裝好了,可是一直擱置在那兒,所以密碼等一些其它細節都忘的差不多了,所以今天就重新部署了一下,並開始積極使用。。。。。。。。。
1,git 安裝:
sudo apt-get install git-core openssh-server openssh-client
$ sudo apt-get install git-core git-gui git-doc
git config --global user.name "用戶名或者用戶ID"
git config --global user.email 郵箱
這兩個選項會在以后的使用過程中自動添加到代碼中
c、創建驗證用的公鑰
這個是比較復雜和困擾大多數人的地方,因為 git 是通過 ssh 的方式訪問資源庫的,所以需要在本地創建驗證用的文件。
使用命令:ssh-keygen -C 'you email address@gmail.com' -t rsa 會在用戶目錄 ~/.ssh/ 下建立相應的密鑰文件
可以使用 ssh -v git@github.com 命令來測試鏈接是否暢通
d、上傳公鑰
在 github.com 的界面中 選擇右上角的 Account Settings,然后選擇 SSH Public Keys ,選擇新加。
Title 可以隨便命名,Key 的內容拷貝自 ~/.ssh/id_rsa.pub 中的內容,完成后,可以再使用 ssh -v git@github.com 進行測試。看到下面的信息表示驗證成功。
2,創建項目:
a、創建本地新項目工作樹
# mkdir new-project
# cd new-project
# git init
# touch README
# git add README (上傳README 文件)
# git commit -m 'first commit'
定義遠程服務器別名origin
# git remote add origin git@github.com:xxx/new-project.git (origin 在這里就是 git@github.com:xxx/new-project.git 的一個別名, 一個 url 鏈接)
本地和遠程合並,本地默認分支為master
# git push origin master (執行這一步可能會有報錯)
如果出現報錯為
ERROR: Repository not found.
fatal: The remote end hung up unexpectedly
則代表你的 origin 的url 鏈接有誤,可能是創建錯誤,也可能是這個 git@github.com:xxx/new-project.git url 指定不正確。
重新創建。
如果報錯為 ()
error: src refspec master does not match any.
All I had to do was:
$~ git commit -m 'initial commit'
$~ git push origin master
Success!
b、更新文件:
# vi README
自動commit更改文件
# git commit -a
更新至遠程
# git push origin master
如果報錯的話:
ssh: connect to host github.com port 22: Connection timed out
fatal: The remote end hung up unexpectedly
解決方法:http://www.cnblogs.com/kysnail/archive/2012/03/31.html
c、 創建和合並分支:
#git branch 顯示當前分支是master
#git branch new-feature 創建分支
# git checkout new-feature 切換到新分支
# vi page_cache.inc.php
# git add page_cache.inc.php
Commit 到本地GIT
# git commit -a -m "added initial version of page cache"
合並到遠程服務器
# git push origin new-feature
#
Counting objects: 4, done.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 336 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@github.com:acanoe/hello_world.git
* [new branch] new-feature -> new-feature
root@AC:~/hello_world#
如果new-feature分支成熟了,覺得有必要合並進master
#git checkout master
#git merge new-feature
#git branch
#git push
則master中也合並了new-feature 的代碼
再登錄到GitHub可以看見"Switch Branches"下的分支選項
到這里,基本的操作也就完成了,在以后的操作中或許還會出現各種各樣的問題,所以會繼續更新,下面附一張git的命令表。。。。。。。
以下是參考鏈接:
http://blog.csdn.net/acanoe/article/details/8520330
http://blog.sina.com.cn/s/blog_55465b470100s63h.html
http://www.open-open.com/lib/view/open1332904495999.html
http://blog.csdn.net/gemmem/article/details/7290125
http://www.linuxsir.org/bbs/thread281294.html
http://www.iteye.com/topic/732199
http://www.stylejar.com/archives/ubuntu_install_git_server.html
http://www.oschina.net/question/54100_25448
http://blog.csdn.net/batoom/article/details/6594260
http://artori.us/git-github-usage/