ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • macOS 에서 Git 프로젝트 업로드
    DevOps/Git 2023. 3. 24. 01:55

     

    Git 과 macOs 연동부분, 그 과정에서 발생했던 error들을 정리하고자 한다     😫

     

     


    1. project upload

     

    ① git repository 에 commit 하고자 하는 프로젝트를 선택한다.

    • "서비스" -> "폴더에서 새로운터미널 열기" 클릭 (code editor terminal 사용해도 상관없음)

     

    // git 초기화 (일반폴더 -> git repository 변환)
    $ git init

     

     

     

    ② git 상태 확인

    • 붉은글씨로 commit 해야할 파일을 표시해줌

     

    //git 상태확인
    $ git status

     

     

    ③ commit 과정

     

    //git add 파일/디렉토리 경로> : 해당경로에 commit 파일추가
    $ git add .

    // commit 및 comment 추가
    $ git commit -m "전달 메시지"

     

     

    ④ 생성된 repository에 프로젝트 추가

     

    // 레파지토리에 프로젝트 추가 (git에서 HTTPS 주소 복사)
    $ git remote add origin <repository에서 복사한주소>

     

    • 프로젝트를 잘못 추가했을시 remove 명령어
    //원격저장소 제거
    git remote remove origin
    
    //과거 내역 reset
    git reset HEAD^

     

     

    ⑤ push / pull 과정

     

    //push
    // --force 추가시 강제 적용
    $ git push origin master
    
    //pull
    $ git pull origin master

     

    • master라는 이름이 없다고 error 발생 .. branch 명을 꼭 확인해주자!

     

     

     

     


    2. Error 대처방법 

     

    ① branch 명을 바꿨는데도 pull 과정에서 error 가 발생했다.

    (local에 존재하지 않는 read.md 파일이 repository에 존재하여 발생)

     

     

    • merge 작업이 필요

     

    //fast-forward only option off
     git config --unset --global pull.ff
    
    //hint를 따라 merge process 진행
    //hint:   git config pull.rebase false  # merge (the default strategy)
    git config pull.rebase false --gloabal
    
    //다시 pull
    git pull origin main
    
    //충돌 확인후 merge
    git add .
    git commit -m "Merge into develop"

    6

     

    • 연결된 history가 없다며 history error가 발생

     

    //allow 처리
    //refusing to merge unrelated histories
    git pull origin main --allow-unrelated-histories

     


     

    Pull 없이 push 경우 기존 내용 삭제 문제가 생길  있다.

     

    //순차적으로 실행
    git init 
    git add .
    git commit -m “message”
    git remote add origin main
    git push -u origin main
    
    //Master branch가 없어서 발생하는 오류일시
    git checkout -b ‘main’
    git push origin main

     

     


     

    ⑦ git push 할때 username, password를 물어보는 경우 (Username for 'https://github.com')

    • HTTPS URL의 경우 username, password 를 물어본다.
    • git remote -v 로 확인시, HTTPS 로 url이 시작한다면, 설정을 바꾸어준다.

     

     

    • SSH Tab에서 URL을 복사

     

     

    • HTTPS URL 을 SSH URL로 변경

     

    //HTTPS -> SSH URL 변경
    git remote set-url origin "SSH URL"
    
    //git remote -v 로 확인시 "https://" -> "git@" 로 변경됨

     

     


     

    ③ Permission denided 발생의 경우 (ssh-key 생성)

     

    git@github.com: Permission denied (publickey).
    fatal: Could not read from remote repository.
    Please make sure you have the correct access rights
    and the repository exists.

     

    • SSH URL의 경우, SSH-KEY를 git에 등록해주어야한다.
    • RSA (공개키 암호 알고리즘) 방식의 암호 key 생성
    • 질문의 답에 모두 enter (password 생성 안해도됨)
    • (~/.ssh/id_rsa.pub) 위치에 key 생성

     

    //SSH KEY 생성
    ssh-keygen -t rsa -C “본인 GitHub 계정 이메일”
    
    //key값 확인 (deploy key 등록시 필요)
    //".pub"를 반드시 붙혀야 한다.
    cat ~/.ssh/id_rsa.pub

     

    • SSH and GPG keys -> New SSH Key 클릭
    • 임의의 Title 입력후, key 입력폼에 "cat ~" 명령어로 나온 key 값을 입력 

     

    d

     

    • 생성된 SSH key 확인

     


     

    ④ git repository 에 폴더가 화살표 모양으로 선택안될경우

     

     

    • 서브폴더 .git 폴더 제거 (ex. CSS_work, HTML_work .. 안에 존재하는)
    • 숨김파일 표시 방법

          1) 윈도우(Windows): 파일탐색기 > 상단 보기 탭 > '숨긴 항목' 체크

          2) 맥(Mac): Finder > command+shift+. 키 입력

     

     

     


     

     

    기나긴 여정 끝에 project가 upload 되었다  😀

    이외에도 에러발생시 대처법들을 업로드할 예정이다.

     

     

     

     

     

     

    'DevOps > Git' 카테고리의 다른 글

    How to install Git  (0) 2023.03.24

    댓글

Designed by Tistory.