[git] git 시작하기
0. git 개념
구분 | git | github |
목적 | 분산형 버전 관리 시스템 (VCS) | git, 클라우드 기반의 코드 호스팅 및 협업 플랫폼 |
기능 | 로컬 코드 관리 | 중앙 코드 관리 협업 관리 |
저장소 | Local Repository | Remote Repository |
인터페이스 | 커맨드라인 인터페이스 (CLI) | 웹 UI 및 CLI 제공 |
1. git bash 설치(window 기준)
Git
git-scm.com
2. 생성 및 연결
2.1 github 계정 및 repository 생성
https://github.com 를 통해 계정 생성 후
저장소 생성
2.2 local - remote 연결
: github의 remote - local 사이의 통신 방법으로 HTTPS or SSH
- HTTPS : 명시적 ID/PW 작성 -> 키로거 공격 위험
- SSH : SSH의 비대칭키 사용 -> 명시적 ID/PW 없이 통신 가능
2.3 ssh를 통한 연결 - 1: ssh-keygen 설정
git bash에서 터미널을 통해
Generating a new SSH key and adding it to the ssh-agent - GitHub Docs
Generating a new SSH key and adding it to the ssh-agent - GitHub Docs
After you've checked for existing SSH keys, you can generate a new SSH key to use for authentication, then add it to the ssh-agent.
docs.github.com
위의 링크와 같은 설정을 통해 키 설정
ssh-heygen -t ed25519 -C "사용자 깃계정(=이메일)"
유의 사항으로는 passphrase 설정 시에는 번거로움이 동반되니 enter로 설정 없이 등록
ls -al ~/.ssh
를 통해 키 페어 설정 확인
- id_ed25519(private key)
- id_ed25519.pub(public key)
등록되어 있다면 키 생성 완료
2.4 ssh를 통한 연결 - 2: ssh 키 추가
1) ssh-agent 에 ssh 개인키 추가
ssh-add -K ~/.ssh/id_ed25519
Identity added: /Users/kido/.ssh/id_ed25519 (사용자 깃 계정)
2) repository 에 ssh 공개 추가하기
## key copy
clip < ~/.ssh/id_ed25519.pub
복사한 키를 넣어준 뒤, 등록되었는 지 확인
ssh -T git@github.com
## 아래는 출력
> The authenticity of host 'github.com (IP ADDRESS)' can't be established.
> RSA key fingerprint is SHA256: ~~
> Are you sure you want to continue connecting (yes/no)?
## yes입력
2.5 ssh를 통한 연결 - 3: local - remote 연결
- github의 작업 레포 생성
- git bash를 통해 작업 디렉토리 이동/생성(cd / mkdir)
- 작업 디렉토리 내 git init
- git branch -M main (기본 브랜치명 master -> main)
- git remote add origin git@github.com:<user name>/<target repository name>.git (local에 remote 추가)
- 첫 커밋 파일 생성 및 커밋 내역 생성 후 git push origin -u origin main
참조
ASAC 수업자료
새 SSH 키 생성 및 ssh-agent에 추가 - GitHub Docs
SSH(Secure Shell Protocol)를 사용하여 GitHub의 리포지토리에서 데이터에 액세스하고 쓸 수 있습니다. SSH를 통해 연결할 때 로컬 머신에서 프라이빗 키 파일을 사용하여 인증합니다. 자세한 내용은 SSH
docs.github.com
https://www.sktenterprise.com/bizInsight/blogDetail/dev/2711
GitHub SSH 접속 설정하기 | 개발자 Story | SKT Enterprise
GitHub SSH 접속 설정하기 GitHub에서는 다음 3가지 방법으로 Git접근을 수행할 수 있도록 하고 있다. GitHub는 https 로 접속 ssh 로 인증서를 발급하여 접근하는 방법 git cli 를 이용하여 접근하는 방법 이
www.sktenterprise.com