본문 바로가기
협업툴,가상환경 정리/Git관련

Git - ssh를 이용해 로그인없이 원격저장소 사용하기 ( Github )

by 알 수 없는 사용자 2022. 2. 18.

총 4번의 과정을 거치면 됨

txt 올리려면 1->2->3->4


이후 폴더 추가해서 수정해서 올리고 싶으면 5번 하면됨

 

 

기본개념 설명

더보기

더보기

출처 : https://www.youtube.com/watch?v=78rykXw9_0g 

https://codevang.tistory.com/217

https://gangju.tistory.com/12

  • 커밋(Commit) : Git(로컬 저장소)에 파일을 추가하거나 변경 내용을 저장하는 작업
  • 푸쉬(Push) : Github(또는 원격 저장소)에 파일을 추가하거나 변경 내용을 저장하는 작업
  • 풀(Pull) : Github(또는 원격 저장소)에서 파일을 다운로드하는 작업

git 과 github 통신에는 https  와 ssh 통신 방식이 있는데 ssh 로 하면 로그인 필요 없음.

 

1. cmd CLI 창에서  ssh-keygen 으로 생성 한다.  뭘 묻는 부분들은 그냥 'Enter'침.

id_rsa : 기계적으로 sha256으로 만든 비밀번호 key

id_rsa.pub : 공개된 key

 

2. id_rsa.pub 키를 복사 후, 깃헙에 가서 SSH and GPG keys 에 등록

 

3. New repogitories 추가 한 후에 ssh 를 복사

 

4. 아래 사진처럼 입력

핵심 명령어

m@ubuntu:~$ git clone git@github.com:wonhyeok1994/mygit_ssh.git mygit_ssh

                    깃 클론   ssh복붙                                                 디렉토리명

m@ubuntu:~/mygit_ssh$ git add f1.txt        // f1.txt만 add         // git add .   이거는 현재폴더 전부 add       
m@ubuntu:~/mygit_ssh$ git commit -m 1    // commit 할때 같이 넘길 로그 안씀 '1'
m@ubuntu:~/mygit_ssh$ git push origin master

더보기

더보기
m@ubuntu:~$ ls
bk_RosForSwiftAndSwiftPro  Desktop    examples.desktop        mygit     Public     Videos
catkin_ws                  Documents  install_ros_kinetic.sh  opencv    serial
catkin_ws2022_02_14.zip    Downloads  Music                   Pictures  Templates
m@ubuntu:~$ git clone git@github.com:wonhyeok1994/mygit_ssh.git mygit_ssh
Cloning into 'mygit_ssh'...
The authenticity of host 'github.com (15.164.81.167)' can't be established.
ECDSA key fingerprint is SHA256:p2QAMXNIC1TJYWeIOttrVc98/R1BUFWu3/LiyKgUfQM.
Are you sure you want to continue connecting (yes/no)? yes 
Warning: Permanently added 'github.com,15.164.81.167' (ECDSA) to the list of known hosts.
warning: You appear to have cloned an empty repository.
Checking connectivity... done.
m@ubuntu:~$ ls
bk_RosForSwiftAndSwiftPro  Desktop    examples.desktop        mygit      Pictures  Templates
catkin_ws                  Documents  install_ros_kinetic.sh  mygit_ssh  Public    Videos
catkin_ws2022_02_14.zip    Downloads  Music                   opencv     serial
m@ubuntu:~$ cd mygit_ssh/
m@ubuntu:~/mygit_ssh$ gedit f1.txt
m@ubuntu:~/mygit_ssh$ cat f1.txt 
git_test
m@ubuntu:~/mygit_ssh$ git add f1.txt 
m@ubuntu:~/mygit_ssh$ git commit -m 1
[master (root-commit) eac2d3a] 1
 1 file changed, 1 insertion(+)
 create mode 100644 f1.txt
m@ubuntu:~/mygit_ssh$ git push
warning: push.default is unset; its implicit value has changed in
Git 2.0 from 'matching' to 'simple'. To squelch this message
and maintain the traditional behavior, use:

  git config --global push.default matching

To squelch this message and adopt the new behavior now, use:

  git config --global push.default simple

When push.default is set to 'matching', git will push local branches
to the remote branches that already exist with the same name.

Since Git 2.0, Git defaults to the more conservative 'simple'
behavior, which only pushes the current branch to the corresponding
remote branch that 'git pull' uses to update the current branch.

See 'git help config' and search for 'push.default' for further information.
(the 'simple' mode was introduced in Git 1.7.11. Use the similar mode
'current' instead of 'simple' if you sometimes use older versions of Git)

Warning: Permanently added the ECDSA host key for IP address '52.78.231.108' to the list of known hosts.
Counting objects: 3, done.
Writing objects: 100% (3/3), 212 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@github.com:wonhyeok1994/mygit_ssh.git
 * [new branch]      master -> master

 

github 에서 확인

 

 

5. github 수정후 업로드 하기

핵심 명령어

m@ubuntu:~/mygit_ssh$ git add .             //폴더에 있는거 전부 git add

m@ubuntu:~/mygit_ssh$ git status            //git에 add 된거 확인
m@ubuntu:~/mygit_ssh$ git commit -m 1   //commit 시 log 넘길거 x
m@ubuntu:~/mygit_ssh$ git push origin master

 

그냥 폴더만 만들어서 push 하려고 하면 안됨. 폴더안에 txt 파일이든 뭔든 있어야 push가 된다.

 

github 수정전

 

github 수정후

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

댓글