/
TDG20240809 [역량강화]배포 환경 별 git branch 설계 예시

TDG20240809 [역량강화]배포 환경 별 git branch 설계 예시








Overview


  





Remote Branch 현황



구분

용도

비고

Remote

master또는main

TEST PROD 환경에 배포 가능한 상태로 관리되는 브랜치

dev 브랜치로부터의 PullRequest를 통해서만 변경 가능

Remote

dev

개발자가 로컬환경에서 구현한 기능을 반영하여DEV 환경에서 검증하기 위한 브랜치 

mater 브랜치의 코드 변경을위해 활용

Local

master

Remote master브랜치로부터 clone한 로컬의master브랜치

최초 소스 변경 작업 전Remote로부터 동기화 수행필요

Local

dev

개발자가 로컬환경에서 기능을 구현하는용도로 사용되는 임시 브랜치

최초 소스 변경 작업 전Remote로부터 동기화 수행필요



main 브랜치 정책 적용



개발자 1 작업


소스 가져오기


git clone 및 디렉토리 이동

youngdae.kim@youngdae_kim MINGW64 ~
$ git clone https://zerobig-devops4demo@dev.azure.com/zerobig-devops4demo/GiFlowDemo-20220810/_git/GiFlowDemo-20220810 dev1
Cloning into 'dev1'...
remote: Azure Repos
remote: Found 6 objects to send. (18 ms)
Unpacking objects: 100% (6/6), 980 bytes | 16.00 KiB/s, done.

youngdae.kim@youngdae_kim MINGW64 ~
$ cd dev
DevOps4OBBEES/ dev1/          dev2/

youngdae.kim@youngdae_kim MINGW64 ~
$ cd dev1

youngdae.kim@youngdae_kim MINGW64 ~/dev1 (main)
$ ls -rlht
total 5.0K
-rw-r--r-- 1 youngdae.kim 1049089 985 Aug 10 15:23 README.md
-rw-r--r-- 1 youngdae.kim 1049089   7 Aug 10 15:23 svc.txt


브랜치 확인

youngdae.kim@youngdae_kim MINGW64 ~/dev1 (main)
$ git branch
* main

youngdae.kim@youngdae_kim MINGW64 ~/dev1 (main)
$ git branch -a
* main
  remotes/origin/HEAD -> origin/main
  remotes/origin/dev
  remotes/origin/main



브랜치 최신화

youngdae.kim@youngdae_kim MINGW64 ~/dev1 (main)
$ git pull
Already up to date.

youngdae.kim@youngdae_kim MINGW64 ~/dev1 (main)
$ git checkout --track origin/dev
Switched to a new branch 'dev'
Branch 'dev' set up to track remote branch 'dev' from 'origin'.

youngdae.kim@youngdae_kim MINGW64 ~/dev1 (dev)
$ git log --oneline
952c948 (HEAD -> dev, origin/main, origin/dev, origin/HEAD, main) Added svc.txt
1d87295 Added README.md


소스 변경 


커밋 후 브랜치 비교


youngdae.kim@youngdae_kim MINGW64 ~/dev1 (dev)
$ git diff origin/main dev

youngdae.kim@youngdae_kim MINGW64 ~/dev1 (dev)
$ git status
On branch dev
Your branch is up to date with 'origin/dev'.

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:   svc.txt

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        svc2.txt

no changes added to commit (use "git add" and/or "git commit -a")

youngdae.kim@youngdae_kim MINGW64 ~/dev1 (dev)
$ git add .

youngdae.kim@youngdae_kim MINGW64 ~/dev1 (dev)
$ git diff origin/main dev

youngdae.kim@youngdae_kim MINGW64 ~/dev1 (dev)
$ git status
On branch dev
Your branch is up to date with 'origin/dev'.

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        modified:   svc.txt
        new file:   svc2.txt


youngdae.kim@youngdae_kim MINGW64 ~/dev1 (dev)
$ git commit -m "Update svc.txt, add svc2.txt"
[dev f61e5b9] Update svc.txt, add svc2.txt
 2 files changed, 3 insertions(+), 1 deletion(-)
 create mode 100644 svc2.txt

youngdae.kim@youngdae_kim MINGW64 ~/dev1 (dev)
$ git diff origin/main dev
diff --git a/svc.txt b/svc.txt
index 0dc5c78..48dd634 100644
--- a/svc.txt
+++ b/svc.txt
@@ -1,3 +1,5 @@
 1
 2
-3
\ No newline at end of file
+3^M
+4 dev1^M
+5 dev1^M
diff --git a/svc2.txt b/svc2.txt
new file mode 100644
index 0000000..e69de29



커밋 전 로그


커밋 후 로그 : 새로운 커밋 생성 및 dev 브랜치 HEAD 변경

Git은 'HEAD’라는 특수한 포인터가 있다. 이 포인터는 지금 작업하는 로컬 브랜치를 가리킨다.


git diff


git push 

youngdae.kim@youngdae_kim MINGW64 ~/dev1 (dev)
$ git push
Enumerating objects: 6, done.
Counting objects: 100% (6/6), done.
Delta compression using up to 8 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (4/4), 340 bytes | 48.00 KiB/s, done.
Total 4 (delta 0), reused 0 (delta 0), pack-reused 0
remote: Analyzing objects... (4/4) (6 ms)
remote: Storing packfile... done (58 ms)
remote: Storing index... done (85 ms)
To https://dev.azure.com/zerobig-devops4demo/GiFlowDemo-20220810/_git/GiFlowDemo-20220810
   952c948..f61e5b9  dev -> dev

youngdae.kim@youngdae_kim MINGW64 ~/dev1 (dev)
$


Remote dev 브랜치 결과


Pull Request dev → main










개발자 2 작업 (푸시 전) 


소스 가져오기


git clone 및 디렉토리 이동

azure-demo# git clone https://zerobig-devops4demo@dev.azure.com/zerobig-devops4demo/GiFlowDemo-20220810/_git/GiFlowDemo-20220810 dev2
Cloning into 'dev2'...
Password for 'https://zerobig-devops4demo@dev.azure.com':
remote: Azure Repos
remote: Found 11 objects to send. (36 ms)
Unpacking objects: 100% (11/11), 1.46 KiB | 5.00 KiB/s, done.
azure-demo# cd dev2
azure-demo# ls -rlht
total 4.0K
-rwxrwxrwx 1 zerobig zerobig 985 Aug 10  2022 README.md
-rwxrwxrwx 1 zerobig zerobig  25 Aug 10  2022 svc.txt
-rwxrwxrwx 1 zerobig zerobig   0 Aug 10  2022 svc2.txt
azure-demo#


브랜치 확인

azure-demo# git branch
* main
azure-demo# git branch -a
* main
  remotes/origin/HEAD -> origin/main
  remotes/origin/dev
  remotes/origin/main
azure-demo#



브랜치 최신화

azure-demo# git pull
Password for 'https://zerobig-devops4demo@dev.azure.com':
Already up to date.
azure-demo# git checkout --track origin/dev
Branch 'dev' set up to track remote branch 'dev' from 'origin'.
Switched to a new branch 'dev'
azure-demo# git log --oneline
f61e5b9 (HEAD -> dev, origin/dev) Update svc.txt, add svc2.txt
952c948 Added svc.txt
1d87295 Added README.md
azure-demo#


소스 변경


리모트 소스 변경 여부 확인


커밋 후 브랜치 비교

azure-demo# git diff origin/main dev
azure-demo# git add .
azure-demo# git commit -m "Update svc.txt"
[dev 77312ae] Update svc.txt
 1 file changed, 2 insertions(+)
azure-demo# git diff origin/main dev
diff --git a/svc.txt b/svc.txt
index 48dd634..66aa062 100644
--- a/svc.txt
+++ b/svc.txt
@@ -3,3 +3,5 @@
 3
 4 dev1
 5 dev1
+6 dev2^M
+7 dev2^M



커밋 전 로그


커밋 후 로그




개발자 1 작업 (개발자 2 푸시 전)

별도 파일 

소스 변경 및 커밋 후 브랜치 비교


youngdae.kim@youngdae_kim MINGW64 ~/dev1 (dev)
$ git add .
warning: LF will be replaced by CRLF in svc2.txt.
The file will have its original line endings in your working directory

youngdae.kim@youngdae_kim MINGW64 ~/dev1 (dev)
$ git commit -m "Update svc2.txt"
[dev aa128e8] Update svc2.txt
 1 file changed, 2 insertions(+)

youngdae.kim@youngdae_kim MINGW64 ~/dev1 (dev)
$ git fetch origin dev --dry-run
From https://dev.azure.com/zerobig-devops4demo/GiFlowDemo-20220810/_git/GiFlowDemo-20220810
 * branch            dev        -> FETCH_HEAD

youngdae.kim@youngdae_kim MINGW64 ~/dev1 (dev)
$ git push
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), 260 bytes | 43.00 KiB/s, done.
Total 3 (delta 1), reused 0 (delta 0), pack-reused 0
remote: Analyzing objects... (3/3) (25 ms)
remote: Storing packfile... done (60 ms)
remote: Storing index... done (49 ms)
To https://dev.azure.com/zerobig-devops4demo/GiFlowDemo-20220810/_git/GiFlowDemo-20220810
   f61e5b9..aa128e8  dev -> dev


리모트 dev 현황


dev → main Pull Request 수행 




개발자 2 작업 푸시 후 재개

최신화 및 푸시하기


푸시 시행 전 리모트 변경사항 검토 실시 및 최신화 하여 푸시


최신화 git pull 전 파일 내용 확인

azure-demo# cat svc.txt
1
2
3
4 dev1
5 dev1
6 dev2
7 dev2
azure-demo# cat svc2.txt
azure-demo#


git pull 수행

azure-demo# git pull origin dev
Password for 'https://zerobig-devops4demo@dev.azure.com':
From https://dev.azure.com/zerobig-devops4demo/GiFlowDemo-20220810/_git/GiFlowDemo-20220810
 * branch            dev        -> FETCH_HEAD
   f61e5b9..aa128e8  dev        -> origin/dev
Merge made by the 'recursive' strategy.
 svc2.txt | 2 ++
 1 file changed, 2 insertions(+)
azure-demo#

수행 과정에 커밋 창 팝업

병합 커밋 생성


최신화 git pull 후 파일 내용 확인

azure-demo# cat svc.txt
1
2
3
4 dev1
5 dev1
6 dev2
7 dev2
azure-demo# cat svc2.txt
1 d1
2 d1
azure-demo#





git push

azure-demo# git push
Password for 'https://zerobig-devops4demo@dev.azure.com':
Enumerating objects: 9, done.
Counting objects: 100% (8/8), done.
Delta compression using up to 8 threads
Compressing objects: 100% (4/4), done.
Writing objects: 100% (5/5), 643 bytes | 29.00 KiB/s, done.
Total 5 (delta 1), reused 0 (delta 0)
remote: Analyzing objects... (5/5) (25 ms)
remote: Storing packfile... done (64 ms)
remote: Storing index... done (50 ms)
To https://dev.azure.com/zerobig-devops4demo/GiFlowDemo-20220810/_git/GiFlowDemo-20220810
   aa128e8..b3cb19d  dev -> dev
azure-demo#


Pull Request 수행




개발자 1 작업 

최신화 및 변경 작업 실시


최신화 및 작업 환경 준비

youngdae.kim@youngdae_kim MINGW64 ~/dev1 (dev)
$ git fetch origin dev --dry-run
remote: Azure Repos
remote: Found 5 objects to send. (0 ms)
Unpacking objects: 100% (5/5), 623 bytes | 11.00 KiB/s, done.
From https://dev.azure.com/zerobig-devops4demo/GiFlowDemo-20220810/_git/GiFlowDemo-20220810
 * branch            dev        -> FETCH_HEAD
   aa128e8..b3cb19d  dev        -> origin/dev

youngdae.kim@youngdae_kim MINGW64 ~/dev1 (dev)
$ git log --oneline
aa128e8 (HEAD -> dev, origin/dev) Update svc2.txt
f61e5b9 Update svc.txt, add svc2.txt
952c948 (origin/main, origin/HEAD, main) Added svc.txt
1d87295 Added README.md

youngdae.kim@youngdae_kim MINGW64 ~/dev1 (dev)
$ git pull origin dev
From https://dev.azure.com/zerobig-devops4demo/GiFlowDemo-20220810/_git/GiFlowDemo-20220810
 * branch            dev        -> FETCH_HEAD
   aa128e8..b3cb19d  dev        -> origin/dev
Updating aa128e8..b3cb19d
Fast-forward
 svc.txt | 2 ++
 1 file changed, 2 insertions(+)

변경 작업 개시 (svc.txt)

youngdae.kim@youngdae_kim MINGW64 ~/dev1 (dev)
$ vi svc.txt

youngdae.kim@youngdae_kim MINGW64 ~/dev1 (dev)
$ git add .

youngdae.kim@youngdae_kim MINGW64 ~/dev1 (dev)
$ git commit -m "Update svc.txt"
[dev 9e1dacb] Update svc.txt
 1 file changed, 2 insertions(+)

youngdae.kim@youngdae_kim MINGW64 ~/dev1 (dev)
$



개발자 2 작업 

최신화 및 변경 작업 실시


최신화 및 작업 환경 준비

azure-demo# git fetch origin dev --dry-run
Password for 'https://zerobig-devops4demo@dev.azure.com':
From https://dev.azure.com/zerobig-devops4demo/GiFlowDemo-20220810/_git/GiFlowDemo-20220810
 * branch            dev        -> FETCH_HEAD
azure-demo#


변경 작업 개시 (svc.txt)


azure-demo# vi svc.txt
azure-demo#
azure-demo# git add .
azure-demo# git commit -m "Update svc.txt"
[dev c7d180f] Update svc.txt
 1 file changed, 2 insertions(+)
azure-demo# git fetch origin dev --dry-run
Password for 'https://zerobig-devops4demo@dev.azure.com':
From https://dev.azure.com/zerobig-devops4demo/GiFlowDemo-20220810/_git/GiFlowDemo-20220810
 * branch            dev        -> FETCH_HEAD
azure-demo#
azure-demo# git push
Password for 'https://zerobig-devops4demo@dev.azure.com':
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 8 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 344 bytes | 18.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
remote: Analyzing objects... (3/3) (25 ms)
remote: Storing packfile... done (62 ms)
remote: Storing index... done (55 ms)
To https://dev.azure.com/zerobig-devops4demo/GiFlowDemo-20220810/_git/GiFlowDemo-20220810
   b3cb19d..c7d180f  dev -> dev
azure-demo#



리모트 커밋 저오




개발자 1 작업 

최신화 및 변경 작업 실시


최신화 및 작업 환경 준비

youngdae.kim@youngdae_kim MINGW64 ~/dev1 (dev)
$ git fetch origin dev --dry-run
From https://dev.azure.com/zerobig-devops4demo/GiFlowDemo-20220810/_git/GiFlowDemo-20220810
 * branch            dev        -> FETCH_HEAD
   b3cb19d..c7d180f  dev        -> origin/dev
youngdae.kim@youngdae_kim MINGW64 ~/dev1 (dev)
$ git pull origin dev
From https://dev.azure.com/zerobig-devops4demo/GiFlowDemo-20220810/_git/GiFlowDemo-20220810
 * branch            dev        -> FETCH_HEAD
   b3cb19d..c7d180f  dev        -> origin/dev
Auto-merging svc.txt
CONFLICT (content): Merge conflict in svc.txt
Automatic merge failed; fix conflicts and then commit the result.

youngdae.kim@youngdae_kim MINGW64 ~/dev1 (dev|MERGING)
$

Conflict 발생

Conflict 해결

youngdae.kim@youngdae_kim MINGW64 ~/dev1 (dev|MERGING)
$ git status
On branch dev
Your branch and 'origin/dev' have diverged,
and have 1 and 1 different commits each, respectively.
  (use "git pull" to merge the remote branch into yours)

You have unmerged paths.
  (fix conflicts and run "git commit")
  (use "git merge --abort" to abort the merge)

Unmerged paths:
  (use "git add <file>..." to mark resolution)
        both modified:   svc.txt

no changes added to commit (use "git add" and/or "git commit -a")

youngdae.kim@youngdae_kim MINGW64 ~/dev1 (dev|MERGING)
$

vi로 파일 열어 수동으로 정리 후 저장

youngdae.kim@youngdae_kim MINGW64 ~/dev1 (dev|MERGING)
$ git add svc.txt

youngdae.kim@youngdae_kim MINGW64 ~/dev1 (dev|MERGING)
$ git status
On branch dev
Your branch and 'origin/dev' have diverged,
and have 1 and 1 different commits each, respectively.
  (use "git pull" to merge the remote branch into yours)

All conflicts fixed but you are still merging.
  (use "git commit" to conclude merge)

Changes to be committed:
        modified:   svc.txt


youngdae.kim@youngdae_kim MINGW64 ~/dev1 (dev|MERGING)
$ git commit -m "Update svc.txt"
[dev bccf33e] Update svc.txt

youngdae.kim@youngdae_kim MINGW64 ~/dev1 (dev)
$ git status
On branch dev
Your branch is ahead of 'origin/dev' by 2 commits.
  (use "git push" to publish your local commits)

nothing to commit, working tree clean

youngdae.kim@youngdae_kim MINGW64 ~/dev1 (dev)
$ git push
Enumerating objects: 10, done.
Counting objects: 100% (10/10), done.
Delta compression using up to 8 threads
Compressing objects: 100% (6/6), done.
Writing objects: 100% (6/6), 665 bytes | 83.00 KiB/s, done.
Total 6 (delta 1), reused 0 (delta 0), pack-reused 0
remote: Analyzing objects... (6/6) (8 ms)
remote: Storing packfile... done (56 ms)
remote: Storing index... done (63 ms)
To https://dev.azure.com/zerobig-devops4demo/GiFlowDemo-20220810/_git/GiFlowDemo-20220810
   c7d180f..bccf33e  dev -> dev

dev → main PR 수행

개발자 2 작업 


최신화 및 작업 준비 실시


azure-demo# git fetch origin dev --dry-run
Password for 'https://zerobig-devops4demo@dev.azure.com':
remote: Azure Repos
remote: Found 6 objects to send. (0 ms)
Unpacking objects: 100% (6/6), 645 bytes | 4.00 KiB/s, done.
From https://dev.azure.com/zerobig-devops4demo/GiFlowDemo-20220810/_git/GiFlowDemo-20220810
 * branch            dev        -> FETCH_HEAD
   c7d180f..bccf33e  dev        -> origin/dev
azure-demo# git pull origin dev
Password for 'https://zerobig-devops4demo@dev.azure.com':
fatal: Authentication failed for 'https://dev.azure.com/zerobig-devops4demo/GiFlowDemo-20220810/_git/GiFlowDemo-20220810/'
azure-demo# git pull origin dev
Password for 'https://zerobig-devops4demo@dev.azure.com':
From https://dev.azure.com/zerobig-devops4demo/GiFlowDemo-20220810/_git/GiFlowDemo-20220810
 * branch            dev        -> FETCH_HEAD
   c7d180f..bccf33e  dev        -> origin/dev
Updating c7d180f..bccf33e
Fast-forward
 svc.txt | 2 ++
 1 file changed, 2 insertions(+)
azure-demo# cat svc.txt
1
2
3
4 dev1
5 dev1
6 dev2
7 dev2
8 dev1
9 dev1
8 dev2
9 dev2
azure-demo# git log --oneline
bccf33e (HEAD -> dev, origin/dev) Update svc.txt
c7d180f Update svc.txt
9e1dacb Update svc.txt
b3cb19d Merge branch 'dev' of https://dev.azure.com/zerobig-devops4demo/GiFlowDemo-20220810/_git/GiFlowDemo-20220810 into dev
aa128e8 Update svc2.txt
77312ae Update svc.txt
f61e5b9 Update svc.txt, add svc2.txt
952c948 Added svc.txt
1d87295 Added README.md
azure-demo#