tools & libs/git

command line에서 project clone 및 관리

  • -
반응형

command line에서 project clone 및 관리

매번 IDE를 통해서 Project 단위로만 git을 사용하다가 여러개의 프로젝트를 하나의 git repository로 관리할 일이 있어서 방법을 정리해본다.

 

git config --list

먼저 나의 상태를 확인해볼 필요가 있다. git config --list 명령을 통해 현재의 환경 정보를 알아보자. 

$ git config --list
user.name=itsmeyjc
user.email=사용자@이메일
core.excludesfile=D:\workspaces\.gitignore

여러 정보들이 나오지만 신경쓸 정보는 위 3가지 정도이다. user.name과 user.email은 commit 할 때 가져가는 정보니까 알아둘 필요가 있다.

core.excludesfile은 기본 적용되는 .ignorre 의 위치이므로 역시 알아두는 것이 좋겠다.

 

git init

git에서 관리하고 싶은 경로를 초기화 하는 과정이 필요하다. 대상 디렉토리로 이동해서 git init 명령을 입력한다.

$ cd d:\workspaces\spring_boot
$ git init
Initialized empty Git repository in d:/workspaces/spring_boot/.git/

그럼 .git 이라는 숨김 폴더가 생성된다.

 

git add

파일을 관리 대상으로 만들기 위해서는 git add <<파일명>>을 사용한다. 동시에 모든 녀석을 다 넣고 싶으면 git add --all 명령을 이용한다.

$ git add --all

이제 파일들은 staging 상태이다.

 

git commit

파일을 local repository에 저장하기 위해서는 git commit -m "메시지내용" 명령을 사용한다.

$ git commit -m "처음 반영"
[master (root-commit) cd174b3] 처음 반영
 274 files changed, 13855 insertions(+)

 

git remote

gitlab.com 등에서 repository를 생성 후 local repository와 remote repository를 연결하는 과정이 필요하다. 이때 git remote를 사용한다. origin이라는 이름으로 git 주소를 등록한다고 생각하자.

git remote add origin "연결하려는 원격지의 git 주소"

 

git push -u

local repository의 내용을 remote repository에 넣기 위해 git push 명령을 이용한다.  origin의 master branch에 넣는다.

$ git push -u origin master

 

그런데 이 과정에성 생각지 못한 오류가 발생했다. 이 포스트를 쓰고 있는 이유다. ㅜㅜ

git@gitlab.com: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

 

ssh-keygen

서버에 ssh 키를 등록해줘야 하는데 먼저 키를 만들어보자.

$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (C:\Users\itsme/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in C:\Users\itsme/.ssh/id_rsa.
Your public key has been saved in C:\Users\itsme/.ssh/id_rsa.pub.
...

질문들에 대해 계속 엔터로 응수하면 최종적으로 public key가 생성되고 위치가 출력된다. text editor로 id_rsa.pub 파일을 연다.

이제 gitlab.com 등 사이트로 로그인 후 User Settings > SSH Keys 메뉴로 이동해 key 부분에 id_rsa_pub 내용을 붙여 넣고 Add Key를 클릭한다.

 

이제 다시 push 처리를 하면 잘 반영되는 것을 볼 수 있다.

$ git push -u origin master
Enumerating objects: 386, done.
Counting objects: 100% (386/386), done.
Delta compression using up to 8 threads
Compressing objects: 100% (293/293), done.
Writing objects: 100% (386/386), 173.12 KiB | 2.22 MiB/s, done.
Total 386 (delta 80), reused 0 (delta 0)
remote: Resolving deltas: 100% (80/80), done.
To gitlab.com:stgray22/spring-boot-zip.git
 * [new branch]      master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.

 

반응형
Contents

포스팅 주소를 복사했습니다

이 글이 도움이 되었다면 공감 부탁드립니다.