이번 포스트에서는 clone 과 fetch 에 대해서 알아보겠습니다.
clone
원격저장소의 프로젝트를 로컬저장소로 복제하는 명령어
git clone (원격저장소 주소)
TEST@DESKTOP-6UMU4VH MINGW64 ~/Desktop/git_workspace/ex05
$ git clone https://github.com/jeehwan-lee/myapp.git
Cloning into 'myapp'...
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 3 (delta 0), pack-reused 0
Receiving objects: 100% (3/3), done.
다음과 같이 ex05 디렉토리에서 git clone 명령어를 통해 원격저장소의 프로젝트를 가져옵니다.
TEST@DESKTOP-6UMU4VH MINGW64 ~/Desktop/git_workspace/ex05
$ cd myapp/
TEST@DESKTOP-6UMU4VH MINGW64 ~/Desktop/git_workspace/ex05/myapp (master)
$ git remote -v
origin https://github.com/jeehwan-lee/myapp.git (fetch)
origin https://github.com/jeehwan-lee/myapp.git (push)
TEST@DESKTOP-6UMU4VH MINGW64 ~/Desktop/git_workspace/ex05/myapp (master)
$ ls -l
total 0
-rw-r--r-- 1 TEST 197121 0 Jan 3 10:43 프로젝트설정.txt
clone 을 통해 myapp 이라는 디렉토리가 생기게 되며
해당 디렉토리에 github 에 업로드했던 프로젝트가 다운받아진것을 볼 수 있습니다.
git clone (주소) = git init + git remote add origin (주소) + git pull origin master
요약을 하면 위와 같이 정리할 수 있습니다.
clone 은 git 을 초기화하고 원격저장소와 연결한뒤 모든 브랜치를 가져오는 명령어입니다.
fetch
원격저장소의 최신 이력을 가져와서 확인하는 명령어
git fetch origin
pull 과 다른점은 fetch 는 로컬저장소로 브랜치와 프로젝트를 가져오지 않음.
실습
먼저 github 에서 브랜치를 하나 만들어보겠습니다.
github 에서 위 사진의 branches 를 클릭해서 브랜치를 하나 만듭니다.
저는 test 라는 브랜치를 만들었습니다.
git fetch origin 을 입력하면 test 라는 새 브랜치가 생성이 되어있는것을 확인할 수 있습니다.
TEST@DESKTOP-6UMU4VH MINGW64 ~/Desktop/git_workspace/ex05/myapp (master)
$ git fetch origin
From https://github.com/jeehwan-lee/myapp
* [new branch] test -> origin/test
test 브랜치를 가져오기 위해서는 로컬저장소에 test 브랜치를 생성하고 merge 를 하면 됩니다.
TEST@DESKTOP-6UMU4VH MINGW64 ~/Desktop/git_workspace/ex05/myapp (master)
$ git branch test
TEST@DESKTOP-6UMU4VH MINGW64 ~/Desktop/git_workspace/ex05/myapp (master)
$ git checkout test
Switched to branch 'test'
TEST@DESKTOP-6UMU4VH MINGW64 ~/Desktop/git_workspace/ex05/myapp (test)
$ git merge origin/test
Already up to date.
위 과정은 git checkout -b test origin/test 를 통해 빠르게 처리할 수도 있습니다.
git checkout -b test origin/test
= git branch test + git checkout test + git merge origin/test
= git checkout -b test + git pull origin test
git log 를 통해 확인해보면 로컬저장소에 master 와 test 브랜치가 있는것을 알 수 있습니다.
TEST@DESKTOP-6UMU4VH MINGW64 ~/Desktop/git_workspace/ex05/myapp (test)
$ git log
commit e41478b40ffe3bf33754e784a727d29ad9f56b5b (HEAD -> test, origin/test, origin/master, origin/HEAD, master)
Author: jeehwan <tjtojan@naver.com>
Date: Tue Jan 3 10:08:55 2023 +0900
프로젝트 설정
이 포스트는 유튜브에 올라온 메타코딩님의 Git 강의를 보고 정리한 내용입니다.
https://www.youtube.com/@metacoding
'Git' 카테고리의 다른 글
Git - rebase 를 통한 로그관리 (0) | 2023.01.09 |
---|---|
Git - github 프로젝트 push 와 pull (1) | 2023.01.03 |
Git - 3 way merge (0) | 2023.01.03 |
Git - fast forward merge (0) | 2023.01.03 |
Git - reset과 reflog를 통한 복구 (1) | 2022.12.31 |