본문 바로가기
Study with me/TECH!T back-end shcool 7

week_01 GIT 2/2

by 외계나무 2023. 10. 19.

Day 02 - remote repository

 

1. git data 흐름 - workspace에서 remote repository까지

git data flow



2. workspace → index

git add & git status

git bash에서 touch 명령어로 파일들을 새로 만들고, 해당 파일들을 local repository 이전의 임시 저장소인 index에 넣어보자.

Q. 왜 폴더 d는 안보일까?
A. git 정책상 비어있는 폴더는 체크하지 않기 때문에!

git add a ↔ git rm --cached a

파일 a를 index에 넣기 vs index에서 제외(unstage)하기
( Q. 왜 unstage? A. Index를 Staging Area라고도 부름! )

git add a b.txt c 처럼 여러 파일을 나열해서 한꺼번에 add 가능

git add . ↔ git reset

전부 한꺼번에 add하기 vs 한꺼번에 unstage하기

  • 다수의 파일을 한번에 건드릴 때
    • 모든 파일: . (마침표)
    • 숨김 파일 제외 모든 파일: * (아스터리스크 asterisk)
    • 모든 숨김 파일: .* (마침표 & 아스터리스크 asterisk)

*변경한 내역까지 없애고 싶으면 -hard 옵션 추가 : git reset --reset

3. index → local repository

git commit -m "message" & git log

add된 파일들을 local repository에 commit해보자.

Q. commit 이후에 git status에 a가 보이지 않는 이유는?
A. a가 commit되어 local repository에 감으로써, workspace와 local repository 사이의 차이점에서 제외되었기 때문에!

login 안 되어있어서 commit 안된다면,

git config --global user.email "깃헙메일"
git config --global user.name "깃헙아이디"

git config user.email과 git config user.name으로 확인

4. local repository -> remote repository (GitHub)

git push

github의 핵심은 .git을 통한 branch history의 공유

bracn / commit 이동: checkout

git checkout 이전커밋코드
git checkout main

(이전커밋코드는 git log --oneline으로 확인)

**깃헙에서 defalut branch가 master라면?
Setting > repositories에서 master를 main으로 바꾸면 됨


git remote -v로 연결된 remote repository list확인

git remote add origin repo링크
git push origin[repo] main[branch]

 

5. pull / clone (remote repo → workspace)

pull

원하는 폴더에서 git bash here

git init
git config --global init.defaultBranch main
git config --global user.email 이메일
git config --global user.name 깃헙이이디
git remote add origin repo링크
git pull origin main

 

clone

git clone repo링크 >>> 해당 remote repository 폴더 전체를 pull
git clone repo링크 . >>> remote repository의 내용물만 pull

'Study with me > TECH!T back-end shcool 7' 카테고리의 다른 글

week_02 JAVA 3/?  (1) 2023.10.24
week_02 JAVA 2/?  (0) 2023.10.23
week_01 JAVA 1/?  (0) 2023.10.20
WIKI  (0) 2023.10.20
week_01 GIT 1/2  (0) 2023.10.18