Github
Updated:
Git은 open source project로서 remote git server도 설치하여 운영할 수 있다. Github는 remote repository 중하나로 repository 서비스 외에 CI/CD의 다양한 기능을 Github에 합쳐 DevOps 도구로 발전시키고 있다. 즉, Github는 one of Git remote repo services이다.
Github 시작하기
Github repository에 Add a README file을 체크하고 리포지토리를 생성한다.
만약 해당 리포지토리에서 git push를 시도하면 ID와 PASSWORD를 입력하라 하고 이를 입력하면 No more password supported since Aug. 2021라고 알람이 발생하여 지금부터 Token key를 사용하여 push 할 때 해당 과정을 안거치게 할 것이다.
Git remote repo demo - remote branch
- git clone
- Remote repo에는 아무 변경 없이 local repo로 복제해 오는 것
- mkdir repo1; cd repo1
- ls -al
- git clone https://github.com/Lazernes/SE_midterm.git
- git clone https://github.com/Lazernes/SE_midterm.git . : .을 붙이면 폴더안에 폴더가 생기지 않고, 현재 위치에 clone을 할 수 있다.
- cd SE_midterm
- git status
- git init을 하지않아도 git을 사용할 수 있음
- git branch
- main branch임
- git log
- origin/main: remote tracking branch로서 origin이라고 이름붙여진 remote repository에 있는 main이란 브랜치의 local COPY이다. 즉, origin/main은 LOCAL branch이고 origin/main 브랜치는 origin이라는 remote repo를 가리키는 pointer가 아니다.
- ls -al
- github의 repository가 복제되었고 .git도 존재
- git remote
- git remote 명령으로 현재 프로젝트에 등록된 리모트 저장소를 확인할 수 있다. 이 명령은 리모트 저장소의 단축 이름을 보여준다.
- origin branch가 생성됨
- git branch
- git branch -a
- 로컬과 원격 저장소에 있는 모든 브랜치를 확인할 수 있다.
- remotes/origin/HEAD, remotes/origin/main 은 원격 저장소(origin)에 있는 브랜치이다.
- ls -al
- vim file1
- git status
- git add .
- git commit -m ‘file1 modified in local repo’
- git commit -m “message”: vim에서 별도의 메세지를 작성할 필요없이 인라인 형식으로 바로 커밋 메세지 작성
- git commit -a: 별도의 add 명령어를 사용하지 않고 수정된 파일에 대해 add, commit을 한번에 수행한다. 단, 한번도 add되지 않은 파일은 add를 따로 작업 해줘야 한다.
- git commit -am: a,m의 옵션을 합친 형태이다.
- git push origin main
- fatal: Authenticaion failed for ‘https://github.com/Lazernes/SE_midterm.git/’
- git push가 되지 않음을 알 수 있다.
- git push https://Lazernes:token@github.com/Lazernes/SE_midterm.git
- 이제 Github에 들어가면 push되어있는 것을 확인할 수 있다.
위 방법으로 git push를 진행하면 push를 할 때마다 token을 사용해야하는 번거로움이 있다.
그래서 다음과 같은 방법을 사용하면 git push만으로 Github에 push할 수 있다.
- git remote set-url origin https://Lazernes:token@github.com/Lazernes/SE_midterm.git
또 다른 방법이 있다.
- git config –global credential.helper cache
- –global옵션은 전역 Git 설정을 변경하겠다는 것을 의미하며, 사용자의 홈 디렉토리에 있는 .gitconfig파일에 설정이 저장된다.
- cache는 Git 자격 증명을 일정 기간 동안 메모리에 저장하는 방법을 지정한다. 즉, 자격 증명이 한 번 입력되면 일정 기간 동안(약 15분) 메모리에 보관되어 다음 요청에서 다시 입력할 필요가 없게 된다.
- git config –global credential.helper store
- store은 Git이 자격 증명을 파일 시스템에 저장하는 방식을 지정한다.
- git config –global –unset credential.helper
- 저장된 credential을 지울 때 사용된다.
- git fetch origin - 동기화
- Fetch는 commit point 오브젝트와 실제 data를 local repo로 가져오되 아직 local working directory의 파일 시스템에는 반영시키지 않는다.
- 사용자가 필요에 따라 merge 명령을 사용해서 local working directory에 반영해야 한다.
- git pull
- Pull 명령어를 사용하여 fetch+merge 를 동시에 할 수 있으나 fetch 한 다음에 확인 후 merge 하는 것을 권장한다.
- Github main branch에서 f2파일을 수정하였다.
- git pull
- cal f2: f2파일이 수정되었음을 알 수 있다.
Github
Github 데모
- git branch in github
- git merge in github
- Contribution to github repo
- fork(for outsider’s contribution)
- clone: remote repo에서 자신의 local repo로 복제
- fork: 다른 github 계정의 repo를 자신의 github 계정으로 복사
- git 명령이 아니며, github의 편의 기능이다.
Github fork and pull request
fork와 pull request는 git 명령어가 아니라 github의 기능이다. LazernesTest Github계정을 만들어서 SE_midterm repository를 Fork하였다.
이후 다음과 같은 명령어들을 사용했다.
- git clone https//github.com/LazernesTest/SE_midterm.git
- 다른 사람의 remote repository를 내 github remote repository로 가져왔으므로 Lazernes에서 LazernesTest로 바뀌었다.
- 이후 file1을 수정하고 앞에서 한 방법처럼 토큰을 사용해 LazernesTest/SE_midterm으로 push를 하였다.
이제 부터 Pull request를 할 것이다.
Lazernes 계정의 SE_midterm repository에 Pull requests가 온 것을 확인할 수 있다.
이후 Merge pull request를 진행하면 Lazernes/SE_midterm이 수정된 것을 볼 수 있다.
위 과정을 그림으로 보면 다음과 같다.
댓글남기기