branch, Merge


안녕하세요 이번에는 git을 이용해서 branch를 생성하고 Merge를 해봤습니다.


1. 테스트 파일 COMMIT & PUSH


test.html이라는 파일을 만들고 커밋을 시도 했습니다.


PS C:\gitTest> git add test.html

PS C:\gitTest> git commit -m "first commit"

 

*** Please tell me who you are.

 

Run

 

  git config --global user.email "you@example.com"

  git config --global user.name "Your Name"

 

to set your account's default identity.

Omit --global to set the identity only in this repository.

 

fatal: unable to auto-detect email address (got '윈도우계정@########(none)')



git을 사용할 이메일과 이름을 설정하라는 메시지가 나왔습니다.


아래와 같이 메일과 이름을 기입해줍니다.


PS C:\gitTest> git config --global user.email "이메일주소@이메일.확장자"

PS C:\gitTest> git config --global user.name "이름기입"



아래와 같이 작성한 파일을 커밋해주고 maser로 Push 해줍니다.



PS C:\gitTest> git commit -m "First Test Commit"

[master (root-commit) 61e65d3] First Test Commit

 1 file changed, 8 insertions(+)

 create mode 100644 test.html


PS C:\gitTest> git push -u origin master

Enumerating objects: 3, done.

Counting objects: 100% (3/3), done.

Delta compression using up to 8 threads

Compressing objects: 100% (2/2), done.

Writing objects: 100% (3/3), 280 bytes | 280.00 KiB/s, done.Total 3 (delta 0), reused 0 (delta 0)

remote:

remote: Create a pull request for 'master' on GitHub by visiting:

remote:      https://github.com/레퍼지토리명/pull/new/masterremote:

To https://github.com/레퍼지토리경로/깃명.git * [new branch]      master -> master

Branch 'master' set up to track remote branch 'master' from 'origin'.



PUSH 명령을 실행해야 실제 레퍼지토리로 파일이 올라가게 됩니다.



2. Branch & Merge


아래와 같은 명령으로 브랜치를 생성 및 교체 할 수 있습니다.


PS C:\gitTest> git branch issue1

PS C:\gitTest> git branch

  issue1

* master

PS C:\gitTest> git checkout issue1

Switched to branch 'issue1'

PS C:\gitTest> git branch

* issue1

  master

PS C:\gitTest> git add test.html

PS C:\gitTest> git -m "테이블 추가"



브랜치를 추가로 만들어서 같은곳을 수정 후 충돌을 내 봤습니다.


PS C:\gitTest> git branch issue3

PS C:\gitTest> git branch

  issue1

  issue3

* master

PS C:\gitTest> git checkout issue3

Switched to branch 'issue3'

PS C:\gitTest> git add test.html

PS C:\gitTest> git commit -m "내용 변경"

[issue3 d421f0d] 내용 변경

 1 file changed, 1 insertion(+), 1 deletion(-)

PS C:\gitTest> git checkout master

Switched to branch 'master'

Your branch is ahead of 'origin/master' by 1 commit.

  (use "git push" to publish your local commits)



충돌이 날 경우 아래와 같은 메시지와 충돌 난 부분을 확인 할 수 있습니다.


PS C:\gitTest> git merge issue3

Auto-merging test.html

CONFLICT (content): Merge conflict in test.html

Automatic merge failed; fix conflicts and then commit the result.



아래와 같은 merge명령을 통해 merge 할 수 있습니다.


PS C:\gitTest> git merge issue3

Updating 6b3412d..d421f0d

Fast-forward

 test.html | 2 +-

 1 file changed, 1 insertion(+), 1 deletion(-)



병합을 마친 후 PUSH를 하게 되면 정상적으로 수정된 파일이 반영됩니다.

PS C:\gitTest> git push

Enumerating objects: 11, done.

Counting objects: 100% (11/11), done.

Delta compression using up to 8 threads

Compressing objects: 100% (6/6), done.

Writing objects: 100% (9/9), 993 bytes | 331.00 KiB/s, done.

Total 9 (delta 1), reused 0 (delta 0)

remote: Resolving deltas: 100% (1/1), done.

To https://github.com/레퍼지토리/깃명.git

   61e65d3..4b29f1c  master -> master




'Configuration management > git' 카테고리의 다른 글

[GIT] Git 설치 및 GitHub 연동  (0) 2018.12.02

Git 설치 및 GitHub 연동


안녕하세요 Git을 설치하고 GitHub와 연동을 해보려고합니다.




https://gitforwindows.org



1. 위 링크에 접속해서 windows 전용 git설치 파일을 다운받습니다.



Download버튼을 클릭하면 바로 설치가 됩니다.


2. 설치 과정


기본옵션으로 쭉 설치 해주시면 됩니다.



저는 기본 경로대로 설치했습니다.


















3. 설치가 완료 되면 GitHub에 가입한 후 레퍼지토리(저장소)를 생성해줍니다.



가장 먼저 GitHub 가입을 진행했습니다.

꼭 인증이 가능한 메일로 입력해주세요



Create an account 버튼을 클릭합니다.



무료를 선택 해 줍니다.

Continue 버튼을 클릭 해 줍니다.



간단한 설문 조사 입니다.



New Repository 버튼을 클릭 하면 레퍼지토리를 생성 할 수 있습니다.



메일 인증을 하지 않으면 생성이 불가능 합니다.



레퍼지토리 명과 설명을 기입 해 줍니다.


Public은 모두에게 공개가 되고, Private은 공개가 되지 않는데

Private은 유료 이기때문에 저는 Public 을 선택 했습니다.



연동 할 URL을 복사 해 둡니다.



4. 레퍼지토리 생성이 완료 되면 git을 사용할 폴더에서 아래와 같은 명령을 실행 합니다.



git init 명령을 사용 하면 해당 폴더에 git 명령을 사용 할 수 있습니다.



git remote add origin 위에서 복사한 레퍼지토리 URL

명령을 수행하면 레퍼지토리와 연동이 됩니다. 



제가 사용하는 VisualCode에서 

git remote -v 명령을 수행하면 정상적으로 연동 된걸 확인 할 수 있습니다.



'Configuration management > git' 카테고리의 다른 글

[GIT] branch, Merge  (0) 2018.12.03

+ Recent posts