git tutorial căn bản - codeto vietnam

11
Git: Feature Branch Workflow - Mỗi một issue/feature sẽ có 1 branch riêng - Không ảnh hưởng tới codebase chính - Branch master không được chứa code lỗi Trung tâm lập trình CODETO@2015/11/09

Upload: ha-anh-son

Post on 12-Feb-2017

283 views

Category:

Engineering


1 download

TRANSCRIPT

Page 1: Git tutorial căn bản - Codeto Vietnam

Git: Feature Branch Workflow

- Mỗi một issue/feature sẽ có 1 branch riêng- Không ảnh hưởng tới codebase chính- Branch master không được chứa code lỗi

Trung tâm lập trình CODETO@2015/11/09

Page 2: Git tutorial căn bản - Codeto Vietnam

Git Workflow

• A developer creates the feature in a dedicated branch in their local repo.

• The developer pushes the branch to a remote repository.

• The developer files a merge request.• The rest of the team reviews the code, discusses it,

and alters it.• The project maintainer merges the feature into the

official repository and closes the merge request.

Trung tâm lập trình CODETO@2015/11/09

Page 3: Git tutorial căn bản - Codeto Vietnam

Branch naming convention

• Trên server git của khách hàng:- Branch “master”: đây là codebase chính của hệ

thống, không được push lên đây- Branch “issue_<redmine_id>”: Là branch do bên

ACV tạo tương ứng với issue #redmine_id trên hệ thống redmine của Khách hàng

- Branch “acv-develop”: Tổng hợp source code mới nhất do ACV phát triển. Phục vụ cho việc test

Trung tâm lập trình CODETO@2015/11/09

Page 4: Git tutorial căn bản - Codeto Vietnam

Khởi tạo git từ repo có sẵn• Tạo folder mới:

mkdir testcd test

• Khởi tạo git: git init

• Ánh xạ “origin” với remote repository:git remote add origin http://git.acvdev.com/test.git

• Nếu là empty remote repo, thì cần tạo master branch trên remote bằng cách push lên server:$ touch README$ git add .$ git commit –m “first commit”$ git push -u origin master (-u: tạo branch trên remote nếu trên server chưa có branch master)

Trung tâm lập trình CODETO@2015/11/09

Page 5: Git tutorial căn bản - Codeto Vietnam

Update source code mới nhất về local

• Lấy source code mới nhất trên remote server và merge vào local folder đang làm việc:$ git checkout issue_1001$ git pull origin issue_1001

• Lấy source code mới nhất trên server về và lưu vào remote repo (không làm ảnh hưởng tới local folder hiện tại):$ git fetch

Trung tâm lập trình CODETO@2015/11/09

Page 6: Git tutorial căn bản - Codeto Vietnam

Tạo branch cho issue mới

• Tạo branch mới từ master branch để xử lý issue 1001 (redmine#1001 của khách hàng):git checkout -b issue_1001 master

• Code trên branch issue_1001• Add file lên branch mới

git add <file-name>• Commit lên local server:

git commit –m “comment message”• Push branch mới lên remote server:

git push origin issue_1001

Trung tâm lập trình CODETO@2015/11/09

Page 7: Git tutorial căn bản - Codeto Vietnam

Tạo merge request trên gitlab

Page 8: Git tutorial căn bản - Codeto Vietnam

Xử lý merge master vào branch issue_x

• Chuyển sang branch issue_x:git checkout issue_x

• Đảm bảo đang ở version mới nhất:git pull

• Merge từ branch master vào issue_xgit pull origin master (có thể dùng: git merge master)

• Đẩy issue lên remote server:git push

Trung tâm lập trình CODETO@2015/11/09

Page 9: Git tutorial căn bản - Codeto Vietnam

Xử lý conflict• Tools:

- TortoiseGit- 192.168.2.5:/home/share/APPS/PROGRAMMING/ bcompare_4.zip

• Cấu hình tortoiseGit:Phải chuột > TortoiseGit > Settings > Diff Viewer:Chọn radio External, nhập đường dẫn beyond compare 4

Trung tâm lập trình CODETO@2015/11/09

Page 10: Git tutorial căn bản - Codeto Vietnam

Xử lý conflict (2)• gặp lỗi conflict khi chạy lệnh pull

git pull origin issue_1002=> Lỗi: Automatic merge failed; fix conflicts and then commit the result

• Phải chuột (lên folder git) > TortoiseGit > Resolve…• Phải chuột lên file cần resolve > Edit conflicts => sử dụng Beyond compare để xử lý• Phải chuột lên file cần resolve > Resolved

Trung tâm lập trình CODETO@2015/11/09

Page 11: Git tutorial căn bản - Codeto Vietnam

Branches:

• Chuyển sang branch khác để làm việc:$ git checkout branch-name

• Xóa remote branch:$ git push origin :old-name

• Đổi tên remote branch:$ git branch new-name origin/old-name $ git push origin -u new-name $ git push origin :old-name

Trung tâm lập trình CODETO@2015/11/09