Github 사용법


Github 시작하기

  • 계정 등록하고 로그인!
  • Personal access token 만들기
    • Settings $\rightarrow$ Developer Settings $\rightarrow$ Personal access tokens $\rightarrow$ Generate new token
    • Updating credentials from the macOS Keychain
      • Keychain Access 앱 실행
      • github의 인터넷 암호 항목 선택
      • 사용자명(계정 칸)과 토큰(암호 보기 누른 뒤 오른쪽 칸) 붙여넣기
  • 새로운 repository 만들기, 협업 멤버 초대하기 등등…

Github 원격 repository 사용하기

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# origin: 원격 저장소 이름. 다른걸로 바꿔도 된다.
git remote add origin {원격 저장소 주소}

# 브랜치 이름을 main으로 바꾸기
git branch -M main

# origin 이란 이름의 원격 저장소의 main 브랜치로 푸쉬하고, 
# git push 만 해도 같은 설정으로 푸쉬하도록 설정.
git push -u origin main

# remote 목록
git remote

# remote 지우기
git remote remove {원격 저장소 이름}

# git 저장소 다운 받기
git clone {원격 저장소 주소}

Push and Pull

1
2
3
4
5
# local => remote
git push

# remote => local
git pull
  • remote와 local의 코드가 둘 다 바뀌었을 때?
1
2
3
4
5
6
7
8
9
10
11
# 양 쪽 다 바뀌었을 땐 push 안됨
git push

# merge 방식으로 합치기
git pull --no-rebase

# rebase 방식으로 합치기
git pull --rebase

# 그 다음에
git push
  • local의 내용 강제로 push 하기
1
git push --force

원격 브랜치 관리

1
2
3
4
5
# 로컬 브랜치만 보기
git branch

# 로컬, 원격 브랜치 모두 보기
git branch --all
1
2
3
4
5
6
7
8
9
10
11
# 로컬에서 브랜치 만들어서 원격에 올리고 싶을 때,
git push -u origin from-local

# 반대로 원격에서 브랜치 만들어서 로컬로 가져올 때는,
# 일단 확인
git fetch
# 원격 브랜치 가져오고, 새 브랜치로 스위치 
git switch -t origin/from-remote

# 원격 브랜치 지우고 싶으면,
git push (원격 이름) --delete (원격의 브랜치명)

Reference

Notes Mentioning This Note

Table of Contents


Share on: