# Git
git是一種分布式版本控制系統,是目前項目管理使用較多的一種工具。
### 下載安裝
### windows
[官網](http://www.git-scm.com/),下載安裝包,直接運行之后命令行就可以運行了。
### Mac
如果是安裝了xcode的話,會自帶一個版本的git。
如果想要安裝新版本的git,推薦使用[**Homebrew**](http://brew.sh/): mac下的apt-get。
安裝brew,它下載的命令是存在放`/usr/local/bin`中的,所以要想正常工作,還需要在PATH中添加這個路徑,在命名行下輸入:`echo export PATH='/usr/local/bin:$PATH' >> ~/.bash_profile`。
### Linux
Linux下可以使用`apt-get install git`來安裝。
### 學習教程
- [最好的中文教程](http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000)
- [Git Magic](http://www-cs-students.stanford.edu/~blynn/gitmagic/intl/zh_cn/): 網上較火的一套教程。
- [GotGithub](https://github.com/gotgit/gotgithub): 一本中文的介紹github使用的書。
- [Git Tutorials](https://www.atlassian.com/git?atl_source=cac-bitbucket-1&atl_medium=ace&atl_campaign=ACE-158-Stash-GIT-on-Bitbucket-CAC_git): bitbucket的教程。
- [Try Git](http://try.github.com/): codeschool教程。
- [Git Immersion](http://gitimmersion.com/index.html): 答題的形式學習git.
- [Learn Version Control with Git](http://www.git-tower.com/learn/)
- [githug](https://github.com/Gazler/githug): Git your game on!
- [git-game](https://github.com/hgarc014/git-game): terminal game to test git skills.
- [Learn Git Branching](http://pcottle.github.io/learnGitBranching/): 形象直觀的圖形化練習網站。
### 使用技巧
### 資料
- [GitHub秘籍](https://github.com/tiimgreen/github-cheat-sheet/blob/master/README.zh-cn.md)
- [Set up Git](https://confluence.atlassian.com/display/BITBUCKET/Set+up+Git): bitbucket教程。
- [Github Help](https://help.github.com/)
- [使用git和github進行協同開發流程](http://livoras.com/post/28)
### 配置文件
一般都在`/user`下,window對應的目錄是`C:\Users\username`,mac和linux對于的就是用戶主目錄`/Users/username`。配置文件名稱為`.gitconfig`。
通常我們使用git的時候最先會去配置username和email:
~~~
git config --global user.name "FIRST_NAME LAST_NAME"
git config --global user.email "MY_NAME@example.com"
~~~
一般而言,我會使用`git add . -> git commit -m "xxxx" -> git push`的方式提交,第一次git操作的時候,git會給我如下的提示:
~~~
warning: push.default is unset; its implicit value has changed in
Git 2.0 from 'matching' to 'simple'. To squelch this message
and maintain the traditional behavior, use:
git config --global push.default matching
To squelch this message and adopt the new behavior now, use:
git config --global push.default simple
When push.default is set to 'matching', git will push local branches
to the remote branches that already exist with the same name.
Since Git 2.0, Git defaults to the more conservative 'simple'
behavior, which only pushes the current branch to the corresponding
remote branch that 'git pull' uses to update the current branch.
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)
~~~
其實就是告訴我要設置下push.default,執行`git config --global push.default simple`即可。
### 存儲密碼
#### https協議
如果使用的是https協議訪問git倉庫,與服務器端同步的時候每一次都會提示輸入密碼。解決這個問題的方式就是能讓密碼保存起來。
在windows下,我使用的是[git-credential-winstore](http://gitcredentialstore.codeplex.com/)。下載安裝即可使用。
在Mac下,我使用的是[git-credential-osxkeychain](http://github-media-downloads.s3.amazonaws.com/osx/git-credential-osxkeychain)。首先在終端中檢測是否已經有git-credential-osxkeychain,`git credential-osxkeychain`。提示`usage: git credential-osxkeychain <get|store|erase>`, 代表有。
如果沒有,下載這個工具,執行:
~~~
Move the file to the /usr/local/bin directory.
$ sudo mv git-credential-osxkeychain /usr/local/bin/
Make the file an executable:
$ chmod u+x /usr/local/bin/git-credential-osxkeychain
Configure git to use the helper.
$ git config --global credential.helper osxkeychain
# Set git to use the osxkeychain credential helper
~~~
如果存在的話,直接執行`git config --global credential.helper osxkeychain`。
在Linux下,執行`git config --global credential.helper store`。
操作完之后,檢查下`.gitconfig`文件,看是否添加了`[credential]`字段。
如果需要取消設置,執行`git config --unset --global credential.helper`。
#### ssh協議
需要設置ssh的私鑰和公鑰。
### 切換協議
查看當前remote: `git remote -v`。
更新remote: `git remote set-url origin https://git.oschina.net/username/YourRepo`
- 介紹
- 程序員基礎知識
- 字符編碼
- 技術名詞
- 語義化版本
- 命名規范
- 書寫文檔
- 開源協議
- 目錄結構
- 正則表達式
- 平凡之路
- 數據結構與算法
- 堆和棧
- 浮點數類型
- XML和JSON
- 算法學習之路
- 排序算法
- 代碼架構
- 設計模式
- 常用的Javascript設計模式
- 面向對象編程
- 繼承
- 多態
- 封裝
- 面向接口編程
- 代碼評審
- 六種量化你代碼的方式
- 程序員必備的代碼審查(Code Review)清單
- 服務器部署
- AWS簡介
- 網絡知識
- HTTPS, SPDY和 HTTP/2性能的簡單對比
- HTTP狀態碼
- 懂點設計
- 佳作賞析
- 無縫平鋪
- Sketch學習
- 設計與實現的平衡
- 寫點東西
- 使用gitbook
- 合格的PM
- 一個好的產品經理
- 產品經理的技能
- 團隊合作
- 關于招聘
- 培訓新人
- 領導能力
- 獲取知識
- MOOC
- Podcasts
- 英語學習
- 設計學習
- 前端學習
- iOS學習
- 游戲開發
- 關注健康
- 過勞檢測
- 關于睡眠
- 提升效率
- 學會閱讀
- 學會提問
- 善用搜索
- 學會寫作
- 時間管理
- 知識管理
- 文件管理
- 密碼管理
- 制作視頻
- 制作PPT
- 論音樂對效率的影響
- 程序員效率指南
- SOHO
- 創業資源
- Hacker
- 保護隱私
- 關于工作
- 找工作前需要思考的問題
- 原則與技巧
- 關于簡歷
- 其他方面
- 硬件相關
- 常用軟件
- Windows
- 硬件配置
- 系統安裝
- 常用軟件
- Mac
- 通用設置
- 權限問題
- alias設置
- 常用軟件
- 開發環境
- 快捷鍵設置
- 常用終端命令
- dotfiles
- Android
- 常用軟件
- 如何登錄美國區GooglePlay
- 開發工具
- git
- EditorConfig
- node
- shadowsocks
- ST3--Windows篇
- ST3--Mac篇
- gulp
- 字體的選擇
- Emacs
- WebStorm
- tmux
- Sketch
- Sketch中文學習資料
- Trello
- 使用Trello管理項目的經驗
- git進階
- 15分鐘學會使用Git和遠程代碼庫
- GitHub秘籍
- JetBrains
- IDE設置
- 附錄
- 計算機科學與技術
- 網站
- 書籍
- 工具