상세 컨텐츠

본문 제목

Gitlab 프로젝트 업로드 및 다운로드

Programming/git

by 노란날. 2024. 1. 12. 13:25

본문

반응형

프로젝트가 많아지고 파일이 서버와 로컬에 분산되면, 인간의 기억력으로 관리할 수 없는 한계와 마주한다. PC 또는 NAS에 폴더를 만들어 저장하는 방식으로 해결보지만, 결국엔 프로젝트 관리 툴이 사용할 수밖에 없다. 괜히 프로젝트 관리 툴이 있는게 아니다. 대표적으로 Github, Gitlab을 사용하는데, Private 저장소가 필요한 경우 유료를 써야 한다. 아직은 영리 목적 프로젝트가 아닌 만큼, gitlab를 서버에 설치하고, git 명령어를 이용해 프로젝트를 관리해본다.

1. git 설치

우분투에서는 apt install git으로 설치하고, 윈도우에서는 공식 웹사이트에서 Window용 Git Download (git-scm.com/download) 설치하여 사용한다. 설치가 끝나면 프로그램 목록에 "Git Bash" 바로가기를 확인할 수 있다. "Git Bash"는 리눅스 명령어를 사용할 수 있어 다루기 쉽고, 리눅스 콘솔과 동일 명령어로 작동하므로 편하다.

2. 프로젝트 업로드

프로젝트 업로드는 gitlab에서 create project를 통해 저장소를 먼저 생성하고 업로드하는 방법이 있다.

2.1 gitlab create project

2.2 처음 전체 업로드 (git bash or console)

<Global Setup>
$ git config --global user.name "user_name"
$ git config --global user.email "user_id"

<Upload a project>
$ cd 프로젝트 폴더
$ git init --initial-branch=main
$ git remote add origin http://000.000.000.000:8080/user_id/project_name.git
$ git add .
$ git commit -m "Initial commit"
$ git push --set-upstream origin main

2.3 중간 업로드

$ git add .
$ git commit -m "주석"
$ git push origin main

3. 프로젝트 다운로드

<Global Setup>
$ git config --global user.name "user_name"
$ git config --global user.email "user_id"

$ git clone http://000.000.000.000:8080/user_id/project_name.git

Cloning into 'project_name'...
Username for 'http://000.000.000.000:8080': user_id
Password for 'http://user_id@000.000.000.000:8080': user_pw
remote: Enumerating objects: 34, done.
remote: Counting objects: 100% (34/34), done.
remote: Compressing objects: 100% (30/30), done.
remote: Total 34 (delta 0), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (34/34), 16.69 KiB | 5.56 MiB/s, done.

4. 기타 명령어

4.1 저장소

<확인>
$ git remote show
$ git remote show 저장소이름
$ git remote -v
<삭제>
$ git remote rm 저장소이름

오류 1 : remote origin already exists.

$ git remote add origin http://000.000.000.000:8080/user_id/project_name.git
error: remote origin already exists.

<해결방법>
$ git remote remove origin

| 참 조 |
https://jackerlab.com/source-upload-to-gitlab/

반응형

관련글 더보기