SlideShare ist ein Scribd-Unternehmen logo
1 von 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
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
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
Khởi tạo git từ repo có sẵn
• Tạo folder mới:
mkdir test
cd 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
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
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
Tạo merge request trên gitlab
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_x
git 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
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
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
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

Weitere ähnliche Inhalte

Ähnlich wie Git tutorial căn bản - Codeto Vietnam

Git workflow advanced - Trung tâm lập trình Codeto Vietnam
Git workflow advanced - Trung tâm lập trình Codeto VietnamGit workflow advanced - Trung tâm lập trình Codeto Vietnam
Git workflow advanced - Trung tâm lập trình Codeto VietnamHà Anh Sơn
 
Kinh nghiệm triển khai Microservices tại Sapo.vn
Kinh nghiệm triển khai Microservices tại Sapo.vnKinh nghiệm triển khai Microservices tại Sapo.vn
Kinh nghiệm triển khai Microservices tại Sapo.vnDotnet Open Group
 
Hướng dẫn cài đặt & sử dụng git, github
Hướng dẫn cài đặt & sử dụng git, githubHướng dẫn cài đặt & sử dụng git, github
Hướng dẫn cài đặt & sử dụng git, githubnukeviet
 
VNPAY Git Seminar
VNPAY Git SeminarVNPAY Git Seminar
VNPAY Git SeminarMr Slowly
 
Các công cụ cần thiết cho quá trình Reverse Engineering .NET (bản đầy đủ)
Các công cụ cần thiết cho quá trình Reverse Engineering .NET (bản đầy đủ)Các công cụ cần thiết cho quá trình Reverse Engineering .NET (bản đầy đủ)
Các công cụ cần thiết cho quá trình Reverse Engineering .NET (bản đầy đủ)Levis Nickaster
 
[OSS Upstream Training] 8 workflow of an open stack contribution and tools
[OSS Upstream Training] 8 workflow of an open stack contribution and tools[OSS Upstream Training] 8 workflow of an open stack contribution and tools
[OSS Upstream Training] 8 workflow of an open stack contribution and toolsVietnam Open Infrastructure User Group
 
Git Using - pythonvietnam.info
Git Using - pythonvietnam.infoGit Using - pythonvietnam.info
Git Using - pythonvietnam.infoKhánh Nguyễn
 
ITLC HN 14 - Bizweb Microservices Architecture
ITLC HN 14  - Bizweb Microservices ArchitectureITLC HN 14  - Bizweb Microservices Architecture
ITLC HN 14 - Bizweb Microservices ArchitectureIT Expert Club
 
Ứng dụng Git/Github trong hoạt động nhóm cho sinh viên CNTT
Ứng dụng Git/Github trong hoạt động nhóm cho sinh viên CNTTỨng dụng Git/Github trong hoạt động nhóm cho sinh viên CNTT
Ứng dụng Git/Github trong hoạt động nhóm cho sinh viên CNTTMinhNguyen1493
 

Ähnlich wie Git tutorial căn bản - Codeto Vietnam (20)

Guilde GIT.pptx
Guilde GIT.pptxGuilde GIT.pptx
Guilde GIT.pptx
 
Git workflow advanced - Trung tâm lập trình Codeto Vietnam
Git workflow advanced - Trung tâm lập trình Codeto VietnamGit workflow advanced - Trung tâm lập trình Codeto Vietnam
Git workflow advanced - Trung tâm lập trình Codeto Vietnam
 
Bang Cuu Chuong Git | NIIT
Bang Cuu Chuong Git | NIITBang Cuu Chuong Git | NIIT
Bang Cuu Chuong Git | NIIT
 
Google+và+tortoise svn
Google+và+tortoise svnGoogle+và+tortoise svn
Google+và+tortoise svn
 
Tranning git
Tranning gitTranning git
Tranning git
 
Tranning git
Tranning gitTranning git
Tranning git
 
Sapo Microservices Architecture
Sapo Microservices ArchitectureSapo Microservices Architecture
Sapo Microservices Architecture
 
Kinh nghiệm triển khai Microservices tại Sapo.vn
Kinh nghiệm triển khai Microservices tại Sapo.vnKinh nghiệm triển khai Microservices tại Sapo.vn
Kinh nghiệm triển khai Microservices tại Sapo.vn
 
Hướng dẫn cài đặt & sử dụng git, github
Hướng dẫn cài đặt & sử dụng git, githubHướng dẫn cài đặt & sử dụng git, github
Hướng dẫn cài đặt & sử dụng git, github
 
VNPAY Git Seminar
VNPAY Git SeminarVNPAY Git Seminar
VNPAY Git Seminar
 
Các công cụ cần thiết cho quá trình Reverse Engineering .NET (bản đầy đủ)
Các công cụ cần thiết cho quá trình Reverse Engineering .NET (bản đầy đủ)Các công cụ cần thiết cho quá trình Reverse Engineering .NET (bản đầy đủ)
Các công cụ cần thiết cho quá trình Reverse Engineering .NET (bản đầy đủ)
 
Git it
Git itGit it
Git it
 
[OSS Upstream Training] 8 workflow of an open stack contribution and tools
[OSS Upstream Training] 8 workflow of an open stack contribution and tools[OSS Upstream Training] 8 workflow of an open stack contribution and tools
[OSS Upstream Training] 8 workflow of an open stack contribution and tools
 
Git Basic
Git BasicGit Basic
Git Basic
 
Git Using - pythonvietnam.info
Git Using - pythonvietnam.infoGit Using - pythonvietnam.info
Git Using - pythonvietnam.info
 
ITLC HN 14 - Bizweb Microservices Architecture
ITLC HN 14  - Bizweb Microservices ArchitectureITLC HN 14  - Bizweb Microservices Architecture
ITLC HN 14 - Bizweb Microservices Architecture
 
Bizweb Microservices Architecture
Bizweb Microservices ArchitectureBizweb Microservices Architecture
Bizweb Microservices Architecture
 
Git & x codepptx
Git & x codepptxGit & x codepptx
Git & x codepptx
 
Cac bai tap .net
Cac bai tap .netCac bai tap .net
Cac bai tap .net
 
Ứng dụng Git/Github trong hoạt động nhóm cho sinh viên CNTT
Ứng dụng Git/Github trong hoạt động nhóm cho sinh viên CNTTỨng dụng Git/Github trong hoạt động nhóm cho sinh viên CNTT
Ứng dụng Git/Github trong hoạt động nhóm cho sinh viên CNTT
 

Git tutorial căn bản - Codeto Vietnam

  • 1. 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
  • 2. 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
  • 3. 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
  • 4. Khởi tạo git từ repo có sẵn • Tạo folder mới: mkdir test cd 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
  • 5. 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
  • 6. 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
  • 7. Tạo merge request trên gitlab
  • 8. 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_x git 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
  • 9. 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
  • 10. 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
  • 11. 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