Programming/GitHub

[GitHub] Git Bash 명령어

OriginMaster 2021. 10. 26. 00:11
반응형

 

로컬 git bash 설정

 

git init : 로컬 저장소로 사용하겠다고 선언.
git remote add origin $Repository주소  :  로컬 저장소와 깃헙 저장소 연결 (GitHub에 레퍼지토리가 생성되어있어야 함)
git status : 저장소 상태 체크(파일갯수 체크)
git add $파일명  :  local git에 해당 파일을 추가
git add .  : 해당 DIR에 있는 모든 파일을 깃에 추가
git commit -m "message" : 커밋 . -m 메세지 입력.


git push origin master(branch명) : 로컬에 있는 데이터를 git에 push
git pull origin master(branch명) :  git에 있는 데이터를 로컬로 pull

 


github에서 로컬저장소로 가져오기


git clone $Repository주소 : 해당 주소에 있는 데이터를 복제해 온다.

 

clone파일로 pull 해왔을 때, 해당 내용을 git에 push하려면 config 값을 설정해줘야 한다.


  git config --global user.email "you@example.com"
  git config --global user.name "Your Name"

 

 

Branch


git branch : 브랜치 목록을 가져온다
git branch 브랜치이름 : 해당 이름으로 브랜치를 생성한다
git checkout 브랜치 : 해당 커밋에 해당되는 곳으로 HEAD가 넘어간다.
추가) branch 합병(merge)하는 법
git merge 브랜치이름 : 현재의 HEAD와 브랜치를 합병한다
git branch -d 브랜치이름 : 해당 브랜치 삭제

git pull origin <branch명> : 특정 브랜치를 pull 해 온다.</branch명>

 

 

commit 복구

git reset --hard(or soft) $커밋번호

 

 

git history에서 특정파일 제거

 ( 단, 로컬에서도 지워지니 백업할 것)


git filter-branch -f --index-filter 'git rm --cached --ignore-unmatch $'삭제하려는file명(주소포함)' --prune-empty -- --all

 

 

 

push 전엔 반드시 pull이 있다

 

반응형