VSCode와 gitlab의 ssh를 연동하기

짜장킴·6일 전

실무

목록 보기
12/13

1. gitlab 프로젝트의 ssh 주소 복사

2. 원격 저장소 연결

git remote add origin git@gitlab.com:그룹명/프로젝트명.git

2-1. 이미 origin이 있다면 아래처럼 변경

git remote set-url origin git@gitlab.com:그룹명/프로젝트명.git
  • origin = 내 프로젝트가 연결된 원격 저장소 이름
  • git remote -v
origin  https://gitlab.com/idy_dev/2601.ref-web-front.git (fetch)
origin  https://gitlab.com/idy_dev/2601.ref-web-front.git (push)
  • 이런 게 나오면 이미 GitLab이랑 연결돼 있다 = origin이 있다
  • origin이 없으면
  • git remote -v -> 아무것도 안 나옴 -> 이때는 새로 추가해야 함:
git remote add origin git@gitlab.com:...
  • 왜 set-url을 쓰냐?
    이미 origin이 있는데 또 추가하려고 하면:
git remote add origin ... -> 에러남 remote origin already exists.
  • 그래서 기존 origin을 “수정”
git remote set-url origin git@gitlab.com:...

3. ssh 키가 있는지 확인

ls ~/.ssh

아래 파일이 있으면 ssh 키가 이미 있는 상태

id_ed25519
id_ed25519.pub

4. ssh 연결 테스트

ssh -T git@gitlab.com

성공하면

Welcome to GitLab, @아이디!

이렇게 나옴 -> gitlab ssh 인증 완료

5. ssh 키가 없다면 생성

ssh-keygen -t ed25519 -C "GitLab 이메일"

공개 키를 확인한다

cat ~/.ssh/id_ed25519.pub

출력된 내용을 복사해서 GitLab에 등록한다

6. 모든 과정이 끝나면

git pull origin main

7. next 사용할거면

npx create-next-app@latest .

8. 만약 GitLab은 빈 프로젝트 (README만 있음)일 경우

git pull origin main   # README 가져오기
rm README.md           # (선택)
npx create-next-app@latest .
profile
프론트엔드 취준생입니다.

0개의 댓글