규도자 개발 블로그

이미 있는 디렉토리에서 git 설정하기 본문

DevOps/Git

이미 있는 디렉토리에서 git 설정하기

규도자 (gyudoza) 2019. 1. 26. 01:25

이미 있는 디렉토리에서 git 설정하기

다른 사람들은 모르겠지만 나는 이상하게 먼저 git repository를 만들기보단 먼저 작업을 하다가 git을 설정할 때가 많은 것 같다. 하지만 이 방법은 먼저 repo를 만들고 clone을 뜨는 것보다 좀 더 여러과정이 필요해서 글로 남겨놓으려 한다.

#해당 디렉토리로 이동하여 git 초기화
$ git init

#주소 추가
$ git remote add origin {git address}
#혹은 주소 변경
$ git remote set url origin {git address}

#코드 업로드
$ git push origin master

#코드 다운
$ git pull origin master
#히스토리 때문에 안받아지는 경우가 있을 땐
$ git pull origin master --allow-unrelated-histories

가끔씩 gitlab에서는 제공하는 https나 ssh주소로도 소스가 받아지지 않는 경우가 있다. 그땐 아래 명령어를 실행하면 된다.

$ git pull origin master --allow-unrelated-histories https://{gitlab-name}@gitlab.com/{gitlab-name}/{projectname}.git

 

Comments