Jul 02, 2023

Git, Github

깃/깃헙 사용방법
Git, Github
Contents
GIT
section 11-
github 페이지 배포
 
 
[ git clone —single-branch —branch “develop” <github repo 주소> . ]
 
터미널) 깃헙 올리는 방법

// .gitignore git init git status git add . git status git commit -m "" git log // git lg // 저장소 생성 git branch -M main git remote add origin <깃헙repository주소> // 깃헙 이름을 origin으로 정함 git push -u origin main

GIT

$ pwd
현재 작업중인 dir, 현재 있는 경로

$ rm <파일>
파일 삭제

$ rm -rf <폴더 or dir>
폴더 혹은 디렉토리 삭제

$ ls -a
모든 파일 show 숨은 파일(숨은파일은 . 로 시작)

$ cat <파일명>
파일 내용을 확인할 때 사용

$ command + k
터미널 화면 깨끗이

$ git init

$ git add <폴더명 or 파일명>
$ git add .
working dir → stage dir

$ git log —oneline
notion image
 


$ git commit -m ‘message’
$ git add forgotten_file
$ git commit —-amend
수정

notion image
HEAD: main branch의 포인터
HEAD → main / HEAD가 가리키는 branch는 북마크 느낌

$ git branch
viewing branches
*표시가 main branch
notion image

$ git branch -v
viewing branches with commit messages
notion image

$ git branch <branch-name>
creating branches

$ git switch <branch-name>
switching branches

$ git commit -a -m "message"
한 줄 명령으로 stage의 모든 변경사항을 올리는 방법

$ git checkout <branch-name> (구버전)
git switch와 비슷

$ git switch -c <branch-name>
creating & switching
$ git branch -D <branch-name>
deleting branch

$ git branch -m <branch-name>
브랜치 이름 변경

section 7

branch merge
$ git switch main
$ git merge bugfix

merge conflict

resolving conflicts
  1. open up files with merge confilcts
  1. edit the file s
  1. remove the conflict markers in the doc
  1. add your changes and then make a commit

section 10

변경사항 취소 및 시간여행

$ git log —oneline
$ git checkout <commit-hash>(c3656c3)
→ detach HEAD
notion image

이전, 전전, 전전전 커밋으로 돌아가기
$ git checkout HEAD~1
$ git checkout HEAD~2
$ git checkout HEAD~3

가장 최근에 있던 branch로 돌아가기
$ git switch -

변경사항 삭제, 마지막 커밋 내용으로 재설정
$ git checkout HEAD <file>
$ git checkout — <file>

Restore
$ git retore <file-name>

unmodifying files with restore
$ git restore —source HEAD~1 app.js

git add . 한 상태에서(staging file) 특정파일을 unstaging
$ git restore —staged <file-name>

repository를 재설정
$ git reset <commit-hash>
working directory에 그대로 남고 커밋은 삭제됨

git revert
$ git revert <commit-hash>
커밋을 완전히 제거하고 branch pointer를 위로 이동
 

section 11-GIT HUB basic

git clone
$ git clone <url>
 
open . vsc에서 코드 열기

Viewing Remotes
$ git remote -v

Adding a new Remote
(이 url을 이름으로 기억하렴)
$ git remote add <name> <url>
$ git remote add origin <github repository url>
Other commands
$ git remote rename <old><new>
$ git remote remove <name>

Pushing
$ git push <remote> <branch>
ex) $ git push origin main
 
Push in Detail
$ git push <remote> <local-branch>:<remote-branch>
$ git push remote main:empty
 
The -u option
$ git push -u origin main
 

branch 이름을 main으로 변경해줌
$ git branch -M main

$ git clone <다른 사람 깃헙 repo url>
$ git branch -r
그 안에 있는 branch들도 보임
notion image
 
$ git checkout origin/food
notion image

section 12 fetch and pull

 
git pull = git fetch + git merge
$ git pull <remote> <branch>
fetch와 다르게 pull은 HEAD branch를 업데이트함
 
 

$ git switch -c empty
 

삭제
$ rm -rf

github 페이지 배포

  1. $ npm i -D gh-pages
  1. package.json
"homepage": “https:// {깃허브 유저 이름}.github.io/{저장소 이름}/”
  1. script추가
"scripts": { "start": "react-scripts start", "build": "react-scripts build", "predeploy": "npm run build", "deploy": "gh-pages -d build",
  1. react-router-dom 기본 경로 변경

    VIM 빠져나오는 방법
    INSERT모드에서 esc,
    :wq

    notion image

     
     

     
    Share article