Git 명령어 총정리집 (by 코딩알려주는 누나)

*국비 수업관련 자료 깃허브

https://github.com/hrdjava1027/javaStudy

*다른 pc로 커밋하기

깃허브 - 다른 컴퓨터로, 기존 계정의 원격 저장소에 커밋하기

Git 사용순서

  1. 깃허브 회원가입

  2. 로컬pc에서 자격증명

    일반 자격 증명에 깃허브 추가

    github 내에서 토큰 생성후 토큰비번을 암호로 입력

    Untitled

    인터넷 또는 네트워크 주소 >> git:https://github.com

  3. 깃 설치 후 global config 설정 (처음 설치시 필수)

    $ git config --global user.name "name"
    $ git config --global user.email "[email protected]"
    
  4. 하단 순으로 입력

    echo "# JavaStudy" >> README.md git init ⇒ 1. git 초기화 git add README.md

    git add . ⇒ 2. 모든 파일을 추가 commit > push git commit -m "first message" ⇒ 3. commit message (최종적으로 저장소에 업로드) git remote add origin https://github.com/JavaBoy94/JavaStudy.git ⇒ 4. 깃허브 저장소에 연결 git push origin main (또는 master) ⇒ 5. 깃허브에 추가

    git push origin +main(master) ⇒ 강제 push

    git status ⇒ git 상태 git branch branch명 ⇒ 새로운 branch 생성

    *브랜치 덮어쓰기 안될 때

    Git&Github ⎮ not working_everything up-to-date but..

    git checkout branch명 ⇒ 기본 branch를 해당 branch명으로 변경

    *branch 변경 에러시 참고

    [git] 새로 만든 원격 브랜치로 checkout이 안될 때. - error: pathspec did not match any file(s) known to git 해결법

    git merge 저장소명 master(main)branch명 ⇒ master(main) branch를 기준으로 해당 저장소의 모든 branch의 코드를 합침

    *파일, 디렉토리(파일) 삭제

    git rm -r 파일(폴더)이름 ⇒ 로컬, 원격 저장소에 올라간 파일 모두 삭제 (원본도 삭제)

    git rm --cached -r 파일(폴더)이름 ⇒ 원격 저장소에 올라간 파일만 삭제

    .gitiginore 파일

    ⇒ 프로젝트에서 원치 않는 백업파일이나, 로그파일 혹은 컴파일 된 파일들을 Git에서 제외시키는 설정파일 (용량감소, 보안유지)

    *gitignore 자동 생성 사이트

    gitignore.io

    [Git] .gitignore이란? / .gitignore 사용법 💖

    git push 에러 - pull 사용

    error: failed to push some refs to 에러