자주 사용하는 명령어 정리

 

1. Git을 사용하기 전에 SSH Agent 가 키를 적절하게 로딩해야한다.

 

1.1 SSH Agent 에 로딩된 키 목록 표시

mymacbook:test ggil$ ssh-add -l
4096 SHA256:2Csx/g+iw?????????????8fSPH7Ryfg test@gmail.com (RSA)
mymacbook:test ggil$

 

 

 

1.2 SSH Agent 에 키 등록하기. (기본 id_rsa 가 로딩되나 비밀번호가 반영되어 있으면 이 과정을 거쳐야 한다.)

mymacbook:test ggil$ ssh-add -K ~/.ssh/id_rsa
Enter passphrase for /Users/ggil/.ssh/id_rsa: 
Identity added: /Users/ggil/.ssh/id_rsa (test@gmail.com)
mymacbook:test ggil$ 

 

 

1.3 SSH Agent 에 비밀번호가 등록된 키를 사용할 때, 키체인에 비밀번호를 등록해서 자동으로 등록하기.

https://help.github.com/en/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent#adding-your-ssh-key-to-the-ssh-agent

 

1.3.1 ~/.ssh/config 파일을 편집한다.

macbookpro-01:nsmon hgchoi$ vi ~/.ssh/config

1.3.2 아래와 같이 수정한다. 

Host *
  AddKeysToAgent yes
  UseKeychain yes
  IdentityFile ~/.ssh/id_rsa

1.3.3 다시 SSH Agent 에 키를 등록한다.

mymacbook:test ggil$ ssh-add -K ~/.ssh/id_rsa
Enter passphrase for /Users/ggil/.ssh/id_rsa: 
Identity added: /Users/ggil/.ssh/id_rsa (test@gmail.com)
mymacbook:test ggil$ 

 

 

2. Git Push

 

2.1 최종 커밋된 로컬 저장소 내용을 리모트 저장소에 반영하기

mymacbook:test ggil$ git push origin master
Warning: Permanently added the ECDSA host key for IP address '1.1.1.1' to the list of known hosts.
Enumerating objects: 42, done.
Counting objects: 100% (42/42), done.
Delta compression using up to 12 threads
Compressing objects: 100% (21/21), done.
Writing objects: 100% (23/23), 12.63 MiB | 6.65 MiB/s, done.
Total 23 (delta 16), reused 0 (delta 0)
To git.test.domain.io:Group1/test.git
   a27a018..dc6e8cb  master -> master
mymacbook:test ggil$ 

 

 

3. Git Branch

 

3.1 Branch 목록 보기

mymacbook:test ggil$ git branch -r
  origin/HEAD -> origin/master
  origin/master
  origin/branch1
  origin/branch2
mymacbook:test ggil$ 

 

 

4. Git Remote

 

4.1 Remote 정보 보기

mymacbook:test ggil$ git remote -v
origin	git@git.test.domain.io:Group1/test.git (fetch)
origin	git@git.test.domain.io:Group1/test.git (push)
mymacbook:test ggil$

 

4.2 Remote 정보 변경하기

mymacbook:test ggil$ git remote set-url origin git@git.test.domain.io:Group1/test.git
mymacbook:test ggil$

바뀐거 확인

mymacbook:test ggil$ git remote -v
origin	git@git.test.domain.io:Group1/test.git (fetch)
origin	git@git.test.domain.io:Group1/test.git (push)
mymacbook:test ggil$

 

 

5. Git pull

 

5.1 original master 원격 저장소를 로컬 저장소에 반영하기

mymacbook:test ggil$ git pull origin master
From ssh://git.test.domain.io:1234/test/test
 * branch            master     -> FETCH_HEAD
Already up to date.
mymacbook:test ggil$ 

 

 

 

 

+ Recent posts