Git
Git
2019/10/27
2020/02/12 (更新內容)
基本概念
Git是個分散式版本管理系統 (Version Control System),所以,使用Git的使用者都會擁有一份完整的程式碼。Git本身並沒有權限管控,所以,一般而言,會利用git server來協助權限管控。如果不想自己架設git server,可以使用git雲端服務。常用的git雲端服務有:github、 gitlab。
這兩個雲端服務的主要差別在於在github免費的專案都必須是公開的,所以,目前大部分的open source專案都可以在github上找到。也因為github是比較早的服務,所以,使用人數及專案數也遠超過gitlab。目前開放三人以下的專案可以開免費的私密專案 (請參考: Git hub pricing)。在gitlab上,目前不管是公開或私密的專案都是免費的 (請參考: Gitlab pricing)。
$ git config --global user.name "John Doe"
$ git config --global user.email johndoe@example.com
當使用git時,我們會有本地資料庫(local repository)及遠端資料庫(remote repository),通常我們會把遠端資料庫(remote repository)設在git server(github或gitlab)上。git的主要運作方式如下:
Init 建立本地的 repository + 連結remote
Commit (將更動儲存到本地的 repository)
Push (將更動從本地的 repository儲存到遠端的 repository)
Pull (從遠端的repository下載更動)
Branch / Merge (branch就是將程式碼新增一個版本,每個人可以產生自己的branch,完成之後再利用merge,把成果整合回共同的版本/master)
How to adopt a Git branching strategy
Use feature branches for all new features and bug fixes
Merge feature branches into the master branch using pull requests
Keep master branch up-to-date
Conflict
當merge時,可能會產生衝突,當有衝突時,要先解決衝突才能Merge
Rebase
An introduction to Git merge and rebase: what they are, and how to use them
What does rebase mean?
Side effects
Alright, gotcha. But why should I rebase?
Increases tests reliability
Makes debugging easier
Solve conflicts before merging
Intro to Interactive Rebasing in Git and Customizing Vim Preferences
![](https://www.google.com/images/icons/product/drive-32.png)
Gitlab
開新專案
帳號管理
git
安裝
新增repository
建立remote
上傳檔案
先將更動變為Staged Changes
將更動進行Commit
放進local的repository
進行Push
將Commit的檔案推送到gitlab
建立branch
merge branch
工具
Git GUI有點陽春,所以,不少人會使用其他的工具,比較多人使用的有:
GitKraken (Linux, Mac, Windows)
Source Tree (Mac, Windows)
有些人會使用開發工具中的plugin
Brackets
Visual Studio Code
Brackets
with Brackets Git
GitKraken
Visual Studio Code
VS Code的Git功能,是基於本機電腦上安裝的Git套件。如果要使用的話,要先確認Git套件是否已經安裝。若無,請至Git官網的download頁面下載安裝檔以進行安裝。
利用git clone就可以下載一個已經存在的專案
Commit, Push, Pull, Branch
參考資料
Git: 敏捷式軟體開發課程教材
GitLab vs GitHub by Svitla Team
Similarities between GitHub and GitLab
Tracking
Issues
Integrations
Support community
Labels
Description templates
Enterprise solutions
Wiki-based project documentation
Edits
Merge approvals
Revert commits
Difference between GitHub and GitLab
Built-in Continuous Integration/Delivery
GitLab有內建的的免費CI/CD
Authentication
Gitlab只能設腳色,Github的權限設定比較彈性
Private repositories
Gitlab提供免費的私密專案,Github私密專案只能開放三人以下免費
Comment tracking
Github比較完整,Gitlab並沒有
GitHub is more focused on high availability and infrastructure performance while GitLab is more focused on including as many features in a robust and well-integrated platform for a complete and centralized DevOps process.
GitLab vs GitHub: Key differences & similarities
Authentication Levels
Built-in CI / CD & going Beyond CD
Issue Tracking
Import & Export
Integrations
The GitHub community
GitLab Enterprise vs GitHub Enterprise