Dev/Git
Git 간단한 사용법 - remote add origin
Itips
2019. 6. 25. 16:07
반응형
Git clone 을 이용해서 원격의 repository 에 있는 파일 변경 정보들을 로컬에 복제했다.
이 때 원격의 repository 를 기본적으로 origin master 라고 부른다. 여기서 'origin' 은 기본적으로 주어지는 remote branch 에 대한 별칭이며 그외 무엇으로든 변경가능하다. 또한 remote repository 를 한개 이상 추가 하는 것도 가능하다.
3개의 원격 리포지토리 생성을 위해서 3개의 폴더 생성
[~/test] $ mkdir remote1
[~/test] $ mkdir remote2
[~/test] $ mkdir remote3
세개의 폴더에 각각 들어가서 리포지토리 초기화 세팅
[~/test] $ cd remote1
[~/test/remote1] $ git init --bare
Initialized empty Git repository in /Users/brkim/test/remote1/
[~/test/remote1] (master) $ cd ../remote2
[~/test/remote2] $ git init --bare
Initialized empty Git repository in /Users/brkim/test/remote2/
[~/test/remote2] (master) $ cd ../remote3
[~/test/remote3] $ git init --bare
Initialized empty Git repository in /Users/brkim/test/remote3/
remote1 을 원격의 리포지토리로 설정하여 git clone 으로 로컬에 복제본을 만든다.
[~/test/remote3] (master) $ cd ../
[~/test] $ git clone remote1 local
Cloning into 'local'...
warning: You appear to have cloned an empty repository.
done.
[~/test] $ cd local
정상적으로 git master branch 가 생성되었기에 git status 로 현재 상태를 확인할 수 있다.
[~/test/local] (master) $ git status
On branch master
No commits yet
nothing to commit (create/copy files and use "git add" to track)
등록된 remote branch 정보를 확인해보면 remote1 리포지토리가 fetch 와 push 용으로 설정이 되어있다.
[~/test/local] (master) $ git remote -v
origin /Users/brkim/test/remote1 (fetch)
origin /Users/brkim/test/remote1 (push)
remote2 와 remote3 를 두번째 세번째의 원격 리포지토리로 등록해 보겠다.
[~/test/local] (master) $ git remote add second_origin ../remote2
[~/test/local] (master) $ git remote add third_origin ../remote3
remote 리포지토리 정보를 확인해 본다.
[~/test/local] (master) $ git remote -v
origin /Users/brkim/test/remote1 (fetch)
origin /Users/brkim/test/remote1 (push)
second_origin ../remote2 (fetch)
second_origin ../remote2 (push)
third_origin ../remote3 (fetch)
third_origin ../remote3 (push)
* origin, second_origin, third_origin 이라는 별칭응로 remote1, remote2, remote3 의
리포지토리들이 모두 등록이 되어 있음을 확인할 수 있다.
추가로 remote repository 를 지울 때는 아래와 같다.
[~/test/local] (master) $ git remote remove third_origin
반응형