Git

Git 실습 :: 원격 저장소 Github에 코드 push 및 pull

gamjadori 2024. 5. 8. 10:28
728x90

<Git 실습 :: 원격 저장소 Github에 코드 push 및 pull>

1. Github에서 토큰 생성

  • 계정 설정 > Password and authentication > Person access tokens > Developer settings

  • 토큰 생성

  • 클래식 토큰 생성 (이름: github-test)

  • select scopes에서 repo / admin:repo_hook 체크

  • 토큰 생성 후 메모

 

2. 리포지토리 생성

  • 리포지토리 이름: git-basic

<생성 완료>

 

3. 원격 설정

  • 현재 작업 중인 로컬 저장소에 원격 저장소 추가
admin@DESKTOP-4M8LFU2 MINGW64 ~/Desktop/git-basic (main)
$ git status
On branch main
nothing to commit, working tree clean

admin@DESKTOP-4M8LFU2 MINGW64 ~/Desktop/git-basic (main)
$ git remote add origin <https://github.com/mogamjadori/git-basic.git>

 

4. push 명령어로 코드를 원격 저장소에 업로드

admin@DESKTOP-4M8LFU2 MINGW64 ~/Desktop/git-basic (main)
$ git push -u origin main
info: please complete authentication in your browser...
Enumerating objects: 68, done.
Counting objects: 100% (68/68), done.  
Delta compression using up to 6 threads
Compressing objects: 100% (66/66), done.
Writing objects: 100% (68/68), 6.54 KiB | 837.00 KiB/s, done.
Total 68 (delta 22), reused 0 (delta 0), pack-reused 0       
remote: Resolving deltas: 100% (22/22), done.
To <https://github.com/mogamjadori/git-basic.git>
 * [new branch]      main -> main
branch 'main' set up to track 'origin/main'.
  • 해당 명령어를 입력하면 Connect to GitHub 화면이 뜸

 

  • 연결 후 GitHub 리포지토리에서 업로드 된 리소스 확인

  • 로그 기록 확인 가능

 

5. 파일 수정 후 GitHub에 반영

<leopards.yaml>

  • 매니저를 Nicholas로 변경
team: Leopards

manager: Nicholas

coach: Melissa
members:
- Linda
- William
- David
- Olivia
- Evie
  • 현재 상태 확인
  • 원격 저장소 origin과 연결된 main 브랜치에서 작업
  • leopards.yaml에 수정사항이 있고, 이가 반영되지 않음
admin@DESKTOP-4M8LFU2 MINGW64 ~/Desktop/git-basic (main)
$ git status
On branch main
Your branch is up to date with 'origin/main'.

Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified:   leopards.yaml

no changes added to commit (use "git add" and/or "git commit -a")

 

6. leopards.yaml 파일 수정 커밋

  • git commit -am 옵션을 주면 add 작업을 거치지 않고 바로 커밋 가능
admin@DESKTOP-4M8LFU2 MINGW64 ~/Desktop/git-basic (main)
$ git commit -am "Add Evie to Leopards"
[main 73c4cc4] Add Evie to Leopards
 1 file changed, 2 insertions(+), 1 deletion(-)

 

7. push를 이용해 원격 저장소에 업로드

admin@DESKTOP-4M8LFU2 MINGW64 ~/Desktop/git-basic (main)
$ git push -u origin main
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 6 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 292 bytes | 292.00 KiB/s, done.
Total 3 (delta 2), reused 0 (delta 0), pack-reused 0        
remote: Resolving deltas: 100% (2/2), completed with 2 local objects.
To <https://github.com/mogamjadori/git-basic.git>
   19d426b..73c4cc4  main -> main
branch 'main' set up to track 'origin/main'.

  • GitHub 사이트에서 수정사항 반영 확인

 

  • GitHub에서 코드를 수정하여 이를 로컬 저장소에 반영

1. jaguars.yaml 파일 수정

  • 멤버에 ssalgaga 추가

 

2. 로컬 호스트에서 pull 실행

admin@DESKTOP-4M8LFU2 MINGW64 ~/Desktop/git-basic (main)
$ git pull
remote: Enumerating objects: 5, done.
remote: Counting objects: 100% (5/5), done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 3 (delta 2), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), 948 bytes | 158.00 KiB/s, done.
From <https://github.com/mogamjadori/git-basic> 
   73c4cc4..c319007  main       -> origin/main
Updating 73c4cc4..c319007
Fast-forward
 jaguars.yaml | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
  • jaguars.yaml 파일을 열어 반영 사항 확인