git은 버전 관리 프로그램  /  .git폴더가 local repository

gitHub는 remote repository (백업용)

 

<<프로젝트를 GitHub에서 관리하기>>

1. 기본 브랜치명 변경 - gitHub에서는 기본 브랜치를 main으로 권장

 git branch -M main

2. local repository에서 remote repository로 올리기

 git push -u [gitHub원격저장소 주소] [로컬branch명]
 
 // ex) git push -u https://github.com/../..git  main

3. 원격 저장소 주소를 변수로 만들기

 git remote add [변수명] [gitHub저장소 주소]
 //ex) git remote add origin https://github.com/../..git
 
 그 이후로 push할 경우
 git push -u origin main
 
 * 저장된 변수명을 보고 싶으면
 git remote -v

4. 원격 저장소에 있는 프로젝트를 내려받기

 git clone [gitHub저장소 주소]

5. 원격 저장소에 있는 프로젝트를 로컬 저장소에 업데이트하기

 git pull [원격저장소 주소]
 git pull [원격저장소 주소] [브랜치명] 	(원격저장소 주소 브랜치명을 가져오기)
 
 * git pull = git fetch + git merge

* 협업시 git pull -> git push 순으로 진행하기

6. Pull Request

 

7. 브랜치 삭제

git push origin -delete [브랜치명] # 원격 브랜치 삭제

8. 원격 레파지토리 변경 내용 확인(병합X)

git fetch
#변경 사항이 있다면
git pull origin develop # develop 브랜치가 변경되었다면 가져와서 동기화하고 conflict발생시 해결

 

 

https://docs.github.com/ko

 

GitHub.com 도움말 문서

GitHub Docs GitHub 여정 중 어디에 있든 도움이 됩니다.

docs.github.com

 


GitHub 개발운영 방법론

 - GitFlow / Github Flow / Trunk-based / Gitlab Flow 등

 - 각 전략은 상황에 따라 유연하게 사

1.GitFlow 개발전략

출처 : https://codingapple.com/course-status/, (2024.10.20)
출처 : https://codingapple.com/course-status/, (2024.10.20)

2.trunk-based 개발전략

 - Github Flow와도 유사

출처 : https://codingapple.com/course-status/, (2024.10.20)
출처 : https://codingapple.com/course-status/, (2024.10.20)

 

'Git' 카테고리의 다른 글

Git 기초  (4) 2024.10.20

이전 회사에서 git을 사용하지 않았고 다시 교육을 받기 시작하면서 필요해져서

git을 사용하려고 했지만 잊어버렸다.

1년을 안 썼다고 잊어버리다니..

이전에도 필요한 명령어만 사용해서 쉽게 잊어버린 것 같았다

이번에 한 번 정리할 필요성을 느껴서 프로젝트를 시작부터 branch 생성, merge까지 진행해보려고 한다

 

<<프로젝트를 Git으로 관리하기>>

Git은 버전관리용 툴이다!!

 

1. Git 설치 확인 및 버전확인

 git --version

2. Git 설정(global)

 git config --global user.email "y*******@gmail.com"

 git config --global user.name "******** *******"
 
 git config --list 	(수정 확인) 
 git config user.email	(수정 확인)
 git config user.name 	(수정 확인)
 
 
 // ------------------------------------------------
 // encoding 설정
 git config --global core.autocrlf true		(windows)
 git config --global core.autocrlf input	(mac os, linux)

3. 프로젝트 폴더를 Git으로 관리

 - 프로젝트 폴더에서 진행

 git init 	(git repository 생성)

 

 - 기존 관리하는 프로젝트가 있을 경우 프로젝트 복사해오기

 git clone [git@github.com:....(기존 프로젝트 경로)]

4. branch 생성

 git branch [브랜치명]

5. branch로 이동

 git switch [가고자하는 브랜치명]
 
 
 // git checkout [브랜치명] = git branch + git switch [브랜치명]

6. 수정한 파일 확인하기

 git status

7. 파일에서 수정한 부분 확인하기(에디에서 지원하는 diffTool로 확인하는 것이 시각적으로 편함) 

 git diff / git diff [commitID]
 // 현재 파일과 최근 commitID / 선택한 commitID 비교하기
 git diff [commitID] [대조군 commitID]
 // commiID와 비교할 commitID 비교하기
 
 //--------------------------------------------------------------
 git difftool
 git difftool [commitID]
 git difftool [commitID] [대조군 commitID]
   
*diffTool Vim에디터에서 vscode에디터로 변경하기
 git config --global diff.tool vscode
 git config --global difftool.vscode.cmd "code --wait --diff $LOCAL $REMOTE"

8. Staging하기(registory에 등록할 파일 고르기)

 git add . 혹은 git add [파일명]

9. Staging한 파일 Staging Area에서 빼기

 git restore --staged [파일명]

10. local Registory에 등록하기

 git commit -m "commit 메세지"

11. commit 내역 확인하기 / commit ID 확인하기

 git log --all --oneline --graph

12. branch 합치기(merge)

 git switch [적용할 branch] 	(적용하려는 branch로 이동)
 git merge [가져올 branch]

- merge는 다음 2가지로 진행됨
<3-way merge>(일반 merge)
<fast-forward merge>(일반 merge와 과정은 같음)
(적용할 branch가 branch하기 전과 동일한 경우 merge하면 
가져오려는 branch가 됨(적용할 branch는 변경사항이 없고 가져오려는 branch가 최신이므로))
* 만약 fast-forward merge에서 적용할 branch를 새로 만들고 싶다면
 git merge --no-ff [합치러는 branch]
 
 
 * 브랜치 합치는 중 conflict 발생할 경우
 conflict 발생한 파일 열어서 conflict부분 수정
 -> git add [수정한 파일]
 -> git commit -m "충돌 해결"
 ====> 충돌 해결하고 merge 완료

13. 작성 중에 최신 main branch가 변경했을 경우(rebase)

 작성 중에 main branch가 변경되어서 적용해야 하고 나머지 작업을 마저할 경우

conflict 발생할 가능성이 높지만 수정하고 commit하기

// 작성중인 branch에서 명령어 사용
 git rebase [가져올 main branch]

14. 자잘한 branch commit 내역 제외하고 merge하기(squash and merge)

 git switch [적용할 branch]
 git merge --squash [가져올 branch]

15. 필요없는 branch 삭제하기

 git branch -d [브랜치명] 	(merge 완료된 브랜치 삭제)
 git branch -D [브랜치명] 	(merge 안된 브랜치 삭제)

16. 오픈소스(gitHub, gitLab) 올리기

 git push -u [gitHub 주소] [브랜치명]

추가적인 명령어

(1) 파일 복구 (restore)

 // 특정 파일을 이전 커밋의 파일로 복구
 git restore [파일명]
 
 // 특정 파일을 commitID 커밋의 파일로 복구
 git restore --source [commitID] [파일명]

(2) 이전 커밋에서 진행한 변경사항을 삭제 후 현재 커밋에서 새로운 커밋 생성 (revert)

 git revert [commitID]
 
 // 그러면 revert commit 메시지를 작성해야 함
 // 새로운 commit 생성

(3) 이전 커밋ID로 시점을 복구 (restore) - 그러면 이전 커밋ID 이후의 내용은 삭제됨 => 협업시 사용X

 git restore --hard [이동하고픈 커밋ID]

'Git' 카테고리의 다른 글

GitHub 기초 / 개발 방법론  (2) 2024.10.20

+ Recent posts