2019년 4월 22일 월요일

Git 사용해 보기.





우선 Synology NAS에 Git 서버를 설치하고, SSH 포트를 오픈해주고,
사용자 설정에서 홈디렉토리 사용으로 한후 git용 계정을 하나 만들어주고,
Git 서버에서 해당 계정을 git으로 사용 한다고 지정 해준다.



putty를 이용해서 접속 SSH로 접속 한다. (admin / Password)
프롬프트에서 sudo -i 를 입력해서 루트 권한을 얻고,git 계정용 홈디렉토리로 이동 한후 기본 설정을 한다.

sudo -i
cd /volume1/homes/git/
mkdir daedo.git
cd daedo.git
git init --bare
cd ..
chown -R git:users daedo.git
cd daedo.git
git update-server-info

클라이언트에서 git bash 를 띄운후 초기 설정을 한다.

git init
git remote add origin ssh://git@192.168.0.2:/volume1/homes/git/daedo.git
git push -u origin master

설정을 잘못해서 다시 할거라면 기존 설정을 삭제 할 수 있다.

git remote rm origin

아니면 .git 이라는 숨김폴더로 이동 해서 config 파일을 수정해 주면 된다.
기타 설정값을 넣을수 있다.

git config credential.helper wincred
git config user.name "Haesup"
git config user.email haesup@MyEmail.kr
git config --global core.quotepath off
git config --global core.eol native
git config --global core.autocrlf true
git add .
git commit -m "First commit"
git status
git push -u origin master

이것역시 config 파일을 수정 하면 수정이 가능 하다.
클라이언트 접속 정보를 캐쉬 하거나 저장 할수도 있다.

git config --global credential.helper 'cache --timeout=864000'
git config --global credential.helper wincred

위에서 wincred 에 경우 윈도우에 경우에 해당되고 osx나 리눅스는 값이 다르다.
자세한 설정은 https://git-scm.com/book/en/v2/Git-Tools-Credential-Storage 링크를 참고.
이제 git bash에서 SSH 키를 만들어 준다.

ssh-keygen -t rsa -C "git@ip.MyGitServer.kr"
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/Haesup/.ssh/id_rsa):
/c/Users/Haesup/.ssh/id_rsa already exists.
Overwrite (y/n)? y
Enter passphrase (empty for no passphrase):
Enter same passphrase again: [엔터키]
Your identification has been saved in /c/Users/Haesup/.ssh/id_rsa.
Your public key has been saved in /c/Users/Haesup/.ssh/id_rsa.pub.
The key fingerprint is: [엔터키]

SHA256:V9wdDFIfdafADF23sf3fasfa4bZW3I git@ip.MyGitServer.kr
The key's randomart image is:
+---[RSA 2048]----+
| .+...o.=o ..O*. |
| . .o+o. o...o+.|
| . .o o o.o.. .|
| . . + .. |
| . o S . |
| o o. . |
| + o .. +. E |
| . = .. + o+ |
| . .oo+o. |
+----[SHA256]-----+

그리고 윈도우+R 눌러서 C:\Users\%username%\.ssh 을 입력하면 SSH 생성 폴더로 이동이 되며 id_rsa , id_rsa.pub 파일을 볼수 있다.

여기서 id_rsa.pub 파일에 내용을 git 서버에 사용자 홈폴더에 .ssh 폴더를 만들어서 authorized_keys 파일을 만든 후 붙여 넣기 해준다.

cd /volume1/homes/git
mkdir .ssh
vi authorized_keys

vi 편집기가 열리면 i키를 누르고 Shift+Ins 눌러서 붙여 넣기 하면 된다.

그리고 파일및 폴더 권한을 준다.

chmod 755 /volume1/homes/git
chmod 700 /volume1/homes/git/.ssh
chmod 600 /volume1/homes/git/.ssh/authorized_keys

이제 git bash에서 git push 하면 비밀번호 없이 바로 적용 되는것을 확인 할수 있다.
이미 Git 저장소에 커밋 된 파일 무시

git rm -r --cached .

(취소 하려면 git add filename .)

git add .
git commit -m ".gitignore is now working"

특정 파일의 수정사항 무시하기

git update-index --assume-unchanged [file path]

특정 파일의 수정사항 무시 취소하기

git update-index --no-assume-unchanged [file path]

수정사항 무시 파일 조회

git ls-files -v|grep '^h'

댓글 없음:

댓글 쓰기