Tools

[Git]git init 과 git init --bare

뱅타 2021. 9. 14. 10:49

git init 과 git init --bare

bare

bare의 단어 뜻은 '벌거벗은', '나체의', '가리지 않은' 뜻입니다.

git init --bare를 직역하자면 나체의 git init 으로 뜻만 봐도 무엇인가 부족하다는 것을 알 수 있습니다.

차이

git init은 git repository를 생성함과 동시에 작업 공간을 함께 생성합니다.

git init --bare는 git repository만 만듭니다.

위에서 언급했듯 git init --bare가 부족한 것은 바로 작업 공간 입니다.


git init으로 만든 repository를 non-bare git repository라고 부르고

git init --bare 로 만든 repository를 bare git repository라고 부릅니다.

non-bare git repository

우리가 git clone을 하거나 git init을 하게 되면 기본적으로 생성되는 repository 입니다.

clone 받은 모든 폴더와 파일들을 볼 수 있고 해당 repo(repository)에서 파일들을 수정, 삭제, 생성 등을 할 수 있습니다.

아래와 같이 생성한 directory에 히스토리와 같은 모든 git 정보들이 들어있는 .git 파일이 존재 합니다.

image-20210909194102007

주의

non-bare repo*에서 *non-bare repo 로는 push가 되지 않습니다.

bare git repository

작업 영역 없이 저장소 만을 생성합니다. 작업 영역이 없기 때문에 안에서 파일을 추가, 수정, 삭제 등을 할 수 없습니다.

image-20210909194459215

Bare와 non-bare의 차이.

image-20210909193039406

사용 방법

bare repository 생성 후 clone 한 뒤 작업 후 push하기.

git init --bare -> clone -> 작업 -> git add -> git commit -> git push

  1. git init --bare 로 현재 위치에 bare repo 생성(저장소).

  2. 작업할 위치로 이동 (cd d:/Eisen/git)

  3. git clone <url> 로 작업할 위치에서 bare repo clone 받기

  4. 작업 ...

  5. git add , git commit, git push 를 하면 됩니다.

non-bare repository 생성 후 작업 후 bare repository 생성한 뒤 push하기

git init -> 작업 -> git add -> git commit -> git init --bare -> git remote add -> git push --set-upstream

  1. git init으로 현재 위치에 non-bare repo 생성(작업공간).

  2. 작업 ...

  3. git add , git commit 으로 git log에 올리기.

  4. 원하는 위치에 저장소 생성 git init --bare d:/Eisen/storage

  5. git remote 에 방금 만든 저장소 추가(test로 추가) git remote add test d:/Eisen/storage

  6. 연결 및 push 하기 git push --set-upstream test master

이후로는 git push 하시면 됩니다.(git push orgin master)

References

https://stackoverflow.com/questions/7861184/what-is-the-difference-between-git-init-and-git-init-bare

728x90
반응형

'Tools' 카테고리의 다른 글

Git 다른 email 등록하기  (0) 2021.10.07
[Git] git command 정리.  (0) 2021.09.29
[Git] 마크다운(Markdown) 사용하기(1)  (0) 2021.08.19
[Windows] IIS로 "Hello World" 띄우기(test1.aspx)  (0) 2021.08.19
[Docker] Docker 컴포넌트  (0) 2021.08.19