Đầu tiên thì git flow … không có sẵn trong command git.
Chúng ta cần phải cài thêm
sudo apt install git-flow
chẳn hạn chúng ta sẽ tạo 1 feature liên quan user authentication
root@LE11-D7891:~/github/devsecops-laboratory# git flow feature start user-authentication
Fatal: Not a gitflow-enabled repo yet. Please run 'git flow init' first.
Vì đây là lần đầu tiên tôi sử dụng git flow nên tôi sẽ cần setup run git flow init
Nim chỉ có một chỗ hơi khó hiểu Version tag prefix?
nếu bạn khai báo chỗ này khai là v thì ở các bước sau:
Git flow hỏi muốn tạo tag gì?
Bạn trả lời 2.0.0
thì Git flow sẽ tạo 1 tag là v2.0.0 và push lên trên git
root@LE11-D7891:~/github/devsecops-laboratory# git flow init
Which branch should be used for bringing forth production releases?
- develop
- master
Branch name for production releases: [master]
Which branch should be used for integration of the "next release"?
- develop
Branch name for "next release" development: [develop]
How to name your supporting branch prefixes?
Feature branches? [feature/]
Bugfix branches? [bugfix/]
Release branches? [release/]
Hotfix branches? [hotfix/]
Support branches? [support/]
Version tag prefix? [] v
Hooks and filters directory? [/root/github/devsecops-laboratory/.git/hooks]
Khi bạn run “git flow feature start helm-chart-add” nó sẽ tạo branch feature/helmchart-add từ branch develop và move workspace của bạn sang branch feature/helmchart-add
root@LE11-D7891:~/github/devsecops-laboratory# git flow feature start helm-chart-add
Switched to a new branch 'feature/helmchart-add'
Summary of actions:
- A new branch 'feature/helmchart-add' was created, based on 'develop'
- You are now on branch 'feature/helmchart-add'
Now, start committing on your feature. When done, use:
git flow feature finish helmchart-add
root@LE11-D7891:~/github/devsecops-laboratory# git branch
develop
* feature/helmchart-add
master
Sau đó bạn dụng lệnh git flow feature publish helm-chart-add, nó sẽ push branch của bạn lên github và sau đó chuyển workspace của bạn sang branch feature/helmchart-add
git flow feature publish helm-chart-add
Ở bước này tôi thực hiện tạo file helmchart.md và code trong đó
tôi code xong git add và git commit.
root@LE11-D7891:~/github/devsecops-laboratory# vi helmchart.md
root@LE11-D7891:~/github/devsecops-laboratory# git branch
develop
* feature/helmchart-add
master
root@LE11-D7891:~/github/devsecops-laboratory# git status
On branch feature/helmchart-add
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: helmchart.md
no changes added to commit (use "git add" and/or "git commit -a")
root@LE11-D7891:~/github/devsecops-laboratory# git add .
root@LE11-D7891:~/github/devsecops-laboratory# git commit -m"complete add feature"
[feature/helmchart-add d973cf0] complete add feature
1 file changed, 1 insertion(+)
Khi tôi thực hiện run git flow feature finish helmchart-add
Nó sẽ chuyển bạn sang branch develop.
merge code từ feature/helmchart-add sang develop
root@LE11-D7891:~/github/devsecops-laboratory# git flow feature finish helmchart-add
Switched to branch 'develop'
Your branch is up to date with 'origin/develop'.
Updating 6fba75b..d973cf0
Fast-forward
helmchart.md | 1 +
1 file changed, 1 insertion(+)
Deleted branch feature/helmchart-add (was d973cf0).
Summary of actions:
- The feature branch 'feature/helmchart-add' was merged into 'develop'
- Feature branch 'feature/helmchart-add' has been locally deleted
- You are now on branch 'develop'
root@LE11-D7891:~/github/devsecops-laboratory# git branch
* develop
master
Bạn thực hiện đồng bộ code trên master và develop ở local.
root@LE11-D7891:~/github/devsecops-laboratory# git checkout master && git pull
Switched to branch 'master'
Your branch is up to date with 'origin/master'.
Already up to date.
root@LE11-D7891:~/github/devsecops-laboratory# git checkout develop && git pull
Switched to branch 'develop'
Your branch is ahead of 'origin/develop' by 1 commit.
(use "git push" to publish your local commits)
Already up to date.
Bạn run “git flow release start 2.0.0” nó sẽ tạo branch ‘release/2.0.0’ từ ‘develop’
Đưa bạn sang branch release/2.0.0
root@LE11-D7891:~/github/devsecops-laboratory# git flow release start 2.0.0
Branches 'develop' and 'origin/develop' have diverged.
And local branch 'develop' is ahead of 'origin/develop'.
Switched to a new branch 'release/2.0.0'
Summary of actions:
- A new branch 'release/2.0.0' was created, based on 'develop'
- You are now on branch 'release/2.0.0'
Follow-up actions:
- Bump the version number now!
- Start committing last-minute fixes in preparing your release
- When done, run:
git flow release finish '2.0.0'
root@LE11-D7891:~/github/devsecops-laboratory# git branch
develop
master
* release/2.0.0
KHi bạn nhấn “git flow release publish 2.0.0” thì nó sẽ push code ở release/2.0.0 branch lên github.
root@LE11-D7891:~/github/devsecops-laboratory# git flow release publish 2.0.0
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 8 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 289 bytes | 289.00 KiB/s, done.
Total 3 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1), completed with 1 local object.
remote:
remote: Create a pull request for 'release/2.0.0' on GitHub by visiting:
remote: https://github.com/mrnim94/devsecops-laboratory/pull/new/release/2.0.0
remote:
To https://github.com/mrnim94/devsecops-laboratory.git
* [new branch] release/2.0.0 -> release/2.0.0
Branch 'release/2.0.0' set up to track remote branch 'release/2.0.0' from 'origin'.
Already on 'release/2.0.0'
Your branch is up to date with 'origin/release/2.0.0'.
Summary of actions:
- The remote branch 'release/2.0.0' was created or updated
- The local branch 'release/2.0.0' was configured to track the remote branch
- You are now on branch 'release/2.0.0'
Trong local bạn quay về kiểm tra và pull lại branch develop
root@LE11-D7891:~/github/devsecops-laboratory# git checkout develop; git push
Switched to branch 'develop'
Your branch is ahead of 'origin/develop' by 1 commit.
(use "git push" to publish your local commits)
Total 0 (delta 0), reused 0 (delta 0)
To https://github.com/mrnim94/devsecops-laboratory.git
6fba75b..d973cf0 develop -> develop
Trên github bạn thực hiện tạo Pull Request từ release/2.0.0 sang master
Sau đó bạn click merge Pull Request
Deploy the release branch to Staging and perform Staging
Khi bạn gõ: git flow release finish -Fp 2.0.0:
root@LE11-D7891:~/github/devsecops-laboratory# git checkout master && git pull
Switched to branch 'master'
Your branch is up to date with 'origin/master'.
Already up to date.
root@LE11-D7891:~/github/devsecops-laboratory# git checkout develop && git pull
Switched to branch 'develop'
Your branch is up to date with 'origin/develop'.
Already up to date.
root@LE11-D7891:~/github/devsecops-laboratory# git checkout release/2.0.0 && git pull
Switched to branch 'release/2.0.0'
Your branch is up to date with 'origin/release/2.0.0'.
Already up to date.
root@LE11-D7891:~/github/devsecops-laboratory# git flow release finish -Fp 2.0.0
Bạn có thêm dòng Release v2.0.0 – add…
Xong đó nhấn Ctrl + 0 -> enter -> Ctrl + X
Xong đó nhấn Ctrl + 0 -> enter -> Ctrl + X
Branches 'master' and 'origin/master' have diverged.
And local branch 'master' is ahead of 'origin/master'.
Switched to branch 'master'
Your branch is ahead of 'origin/master' by 2 commits.
(use "git push" to publish your local commits)
Switched to branch 'develop'
Your branch is up to date with 'origin/develop'.
Already up to date!
Merge made by the 'recursive' strategy.
Enumerating objects: 2, done.
Counting objects: 100% (2/2), done.
Delta compression using up to 8 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 402 bytes | 402.00 KiB/s, done.
Total 2 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1), done.
To https://github.com/mrnim94/devsecops-laboratory.git
d973cf0..c27400d develop -> develop
Total 0 (delta 0), reused 0 (delta 0)
To https://github.com/mrnim94/devsecops-laboratory.git
d69a9cc..89fe713 master -> master
Enumerating objects: 1, done.
Counting objects: 100% (1/1), done.
Writing objects: 100% (1/1), 218 bytes | 218.00 KiB/s, done.
Total 1 (delta 0), reused 0 (delta 0)
To https://github.com/mrnim94/devsecops-laboratory.git
* [new tag] v2.0.0 -> v2.0.0
To https://github.com/mrnim94/devsecops-laboratory.git
- [deleted] release/2.0.0
Deleted branch release/2.0.0 (was d973cf0).
Summary of actions:
- Latest objects have been fetched from 'origin'
- Release branch 'release/2.0.0' has been merged into 'master'
- The release was tagged 'v2.0.0'
- Release tag 'v2.0.0' has been back-merged into 'develop'
- Release branch 'release/2.0.0' has been locally deleted; it has been remotely deleted from 'origin'
- 'develop', 'master' and tags have been pushed to 'origin'
- You are now on branch 'develop'
Code từ branch ‘release/2.0.0’ được merge vào master
tạo tag v2.0.0 và push lên GitHub
Code của tag v2.0.0 được merge vào devlop
branch release/2.0.0 được xóa
Hotfix branch
root@LE11-D7891:~/github/devsecops-laboratory# git checkout master && git pull
Switched to branch 'master'
Your branch is up to date with 'origin/master'.
Already up to date.
root@LE11-D7891:~/github/devsecops-laboratory# git flow hotfix start 2.0.1
Switched to a new branch 'hotfix/2.0.1'
Summary of actions:
- A new branch 'hotfix/2.0.1' was created, based on 'master'
- You are now on branch 'hotfix/2.0.1'
Follow-up actions:
- Start committing your hot fixes
- Bump the version number now!
- When done, run:
git flow hotfix finish '2.0.1'
root@LE11-D7891:~/github/devsecops-laboratory# git flow hotfix publish 2.0.1
Total 0 (delta 0), reused 0 (delta 0)
remote:
remote: Create a pull request for 'hotfix/2.0.1' on GitHub by visiting:
remote: https://github.com/mrnim94/devsecops-laboratory/pull/new/hotfix/2.0.1
remote:
To https://github.com/mrnim94/devsecops-laboratory.git
* [new branch] hotfix/2.0.1 -> hotfix/2.0.1
Branch 'hotfix/2.0.1' set up to track remote branch 'hotfix/2.0.1' from 'origin'.
Already on 'hotfix/2.0.1'
Your branch is up to date with 'origin/hotfix/2.0.1'.
Summary of actions:
- The remote branch 'hotfix/2.0.1' was created or updated
- The local branch 'hotfix/2.0.1' was configured to track the remote branch
- You are now on branch 'hotfix/2.0.1'
root@LE11-D7891:~/github/devsecops-laboratory# git checkout master; git push
Switched to branch 'master'
Your branch is up to date with 'origin/master'.
Everything up-to-date
root@LE11-D7891:~/github/devsecops-laboratory# git checkout master; git push
Switched to branch 'master'
Your branch is up to date with 'origin/master'.
Everything up-to-date
root@LE11-D7891:~/github/devsecops-laboratory# git checkout hotfix/2.0.1 && git pull
Switched to branch 'hotfix/2.0.1'
Your branch is up to date with 'origin/hotfix/2.0.1'.
Already up to date.
root@LE11-D7891:~/github/devsecops-laboratory# git flow hotfix finish -Fp 2.0.1
Everything up-to-date
Everything up-to-date
Enumerating objects: 1, done.
Counting objects: 100% (1/1), done.
Writing objects: 100% (1/1), 184 bytes | 184.00 KiB/s, done.
Total 1 (delta 0), reused 0 (delta 0)
To https://github.com/mrnim94/devsecops-laboratory.git
* [new tag] v2.0.1 -> v2.0.1
To https://github.com/mrnim94/devsecops-laboratory.git
- [deleted] hotfix/2.0.1
Switched to branch 'develop'
Your branch is up to date with 'origin/develop'.
Deleted branch hotfix/2.0.1 (was 89fe713).
Summary of actions:
- Latest objects have been fetched from 'origin'
- Hotfix branch 'hotfix/2.0.1' has been merged into 'master'
- The hotfix was tagged 'v2.0.1'
- Hotfix branch 'hotfix/2.0.1' has been locally deleted; it has been remotely deleted from 'origin'
- 'develop', 'master' and tags have been pushed to 'origin'
- You are now on branch 'develop'