
원격저장소에 파일을 올려서 백업하고 백업한 파일을 내려받을수가 있습니다.
우선 원격저장소와 연결된 지역저장소에 test.txt라는 파일을 하나 만들고 아무내용이나 작성한뒤 "add a" 라는 메세지로 커밋하겠습니다.
$cd ~
$cd local-test
$vim test.txt
$git add test.txt
$git commit -m "add a"

스테이징되고 지역저장소에 test.txt파일이 대기중입니다.
이제 이를 원격 저장소에 올리기 위해서는 push라는 명령이 필요합니다.
$git push -u origin master

push에 성공했습니다.
위의 명령은 지역 저장소의 브랜치를 origin, 즉 원격 저장소의 master 브랜치로 푸쉬하라는 명령입니다.
여기서 -u 옵션은 지역 저장소의 부랜치를 원격 저장소의 master 브랜치에 연결하기 위한 것으로 처음에 한번만 하면됩니다!
그렇다면 정말 원격 저장소에 잘 올라갔을까요??

다시 깃허브로 돌아가보면 cinetest라는 repository에 파일이 잘 올라가 있습니다.
커밋 메세지도 아까 해주었던 add a라는 메세지로 잘 올라갔네요!
또한 파란색으로 잡아놓은 영역의 1 commit 을 클릭해보세요.

지역저장소에서 커밋했던 내용이 똑같이 올라가 있습니다.
또한 한번이라도 commit을 했다면 그다음부터는 원격저장소에 올리는 방법이 간단해집니다.
vim으로 test.txt파일을 수정한 다음 "add b" 메세지로 다시 커밋해보겠습니다.
$vim test.txt
$git add test.txt
$git commit -m "add b"

이전에 지역저장소의 브랜치와 origin의 master 브랜치를 연결했기 때문에 다시 push 명령을 사용할때는 뒤에 내용을 생략할수 있습니다.
$git push

이제 다시 깃허브로 가서 확인해볼까요?

커밋 메세지가 "add b"로 변경되어있고 2 commit으로 나와있습니다.
또한 test.txt를 눌러 내용을 확인해보면 수정된 내용이 들어있을것입니다.

지역저장소에서 작업후에 원격 저장소에 올리는 방법도 있지만 깃허브에서 직접 커밋하는 방법도 있습니다.

Add file을 누르면 Create new file과 Upload files가 나오는데요.
Create new file을 눌러주세요.

그러면 뭔가 텍스트 편집기처럼 뭔가가 나오는데 위쪽에는 파일이름 아래쪽에는 내용을 작성하시면됩니다.

그리고 아래로 내려보면 커밋메세지를 작성할수 있고 아래 버튼을 눌러서 커밋할수 있습니다.

이제 다시 레퍼지토리로 가면 파일이 하나 더 생겼죠??
test2.txt 를 눌러 파일을 확인해보겠습니다.

제가 적었던 test2 라는 내용이 잘 들어가있습니다.
또한 오른쪽에 있는 연필모양을 누르면 파일을 수정할수도 있으며 오른쪽 휴지통 모양을 누르면 삭제할수도 있습니다.
깃허브에서 test2.txt파일을 만들었지만 로컬저장소에는 test2.txt파일이 아직 없을것입니다.
다시 git bash로 와서 확인해볼까요?
$ls

test.txt파일밖에 존재하지않습니다.
이제 원격저장소에 있는 파일을 내려받아보겠습니다.
$git pull origin master

해당 명령은 origin(원격저장소)에 있는 내용을 master 브랜치로 가져오겠다는 의미입니다.
또한 위와 같은 결과 이면 파일이 잘 내려받아 진것입니다.
$ls

파일이 잘 들어가있습니다!
본 포스팅은 DO it! 지옥에서 온 문서 관리자 깃&깃허브 입문 도서를 참고하며 공부한 내용을 포스팅 하였습니다.

'Git > Github' 카테고리의 다른 글
[Git & GitHub] 여러 PC에서 원격 저장소 함께사용하는법 (0) | 2022.06.26 |
---|---|
[Git & GitHub] 깃허브 SSH(Secure Shell) 원격 접속 (0) | 2022.06.25 |
[Git & GitHub] 원격저장소와 지역저장소 연결 (0) | 2022.06.23 |
[Git & GitHub] 수정중인 파일 되돌리기(git stash) (0) | 2022.06.22 |
[Git & GitHub] branch 관리 (0) | 2022.06.21 |