github에 repository 생성하고 연동, gitignore 초기 설정까지

람다람쥐·2023년 4월 1일
0

이미 컴퓨터에 생성된 파일이 있는 경우 새로운 레포지토리 생성해서 연결할 때

  1. github 홈페이지에서 직접 new repository 생성

    gitignore 파일도 선택해서 생성 (필수 아님)
  1. git init
    깃으로 관리하도록 하는 명령어

  2. git remote add origin [깃 주소]
    원격저장소에 연결하기
    git remote -v
    잘 연결됐는지 확인하기
    - 연결됐으면 주소가 뜨고 안됐으면 아무것도 안뜸

깃 연동 해제 명령어
git remote remove origin
다시 git remote -v로 확인

  1. git pull origin main
    원격(깃허브 내 레포지토리)와 로컬(내 컴퓨터 내부적으로만 기록되는 깃)의 상태가 달라서 push할 수 없으므로 원격에 만들어준 gitignore 파일을 가져오는 pull을 함

    error: failed to push some refs to ‘’ 에러 뜨는 경우

    해결방법 1:
    git pull origin main --allow-unrelated-histories
    (로컬 저장소에 있는 프로젝트를 깃허브 사이트를 통해 만든 저장소로 push 하는 경우에 이런 메세지가 뜨는 경우가 있다고 함 - 참고한 블로그)

    해결방법 2: git push origin +main 으로 강제 푸시
    레포지토리 생성 시 gitignore 파일을 생성하지 않았거나 gitignore 파일을 날려도 되는 경우


    이제 평소대로 아래처럼 푸시하면 된다.
git add .
git commit -m ""
git push origin main

깃이그노어 파일 수정하기
https://www.toptal.com/developers/gitignore

java, eclipse 등 선택해서 나오는 코드 .gitignore에 붙여넣기

주의 .project .classpath .settings/ 3개는 지워주자!! 원래 설정이 꼬이기 쉬운 부분이라 ignore처리를 해줘야 하지만 처음 등록할 때 이게 없으면 프로젝트 자체를 못찾을 수 있기 때문에 일단 지워주고 복사하자
참고한 블로그

    # Created by https://www.toptal.com/developers/gitignore/api/eclipse,java
    # Edit at https://www.toptal.com/developers/gitignore?templates=eclipse,java
    
    ### Eclipse ###
    .metadata
    bin/
    tmp/
    *.tmp
    *.bak
    *.swp
    *~.nib
    local.properties
    .settings/
    .loadpath
    .recommenders
    
    # External tool builders
    .externalToolBuilders/
    
    # Locally stored "Eclipse launch configurations"
    *.launch
    
    # PyDev specific (Python IDE for Eclipse)
    *.pydevproject
    
    # CDT-specific (C/C++ Development Tooling)
    .cproject
    
    # CDT- autotools
    .autotools
    
    # Java annotation processor (APT)
    .factorypath
    
    # PDT-specific (PHP Development Tools)
    .buildpath
    
    # sbteclipse plugin
    .target
    
    # Tern plugin
    .tern-project
    
    # TeXlipse plugin
    .texlipse
    
    # STS (Spring Tool Suite)
    .springBeans
    
    # Code Recommenders
    .recommenders/
    
    # Annotation Processing
    .apt_generated/
    .apt_generated_test/
    
    # Scala IDE specific (Scala & Java development for Eclipse)
    .cache-main
    .scala_dependencies
    .worksheet
    
    # Uncomment this line if you wish to ignore the project description file.
    # Typically, this file would be tracked if it contains build/dependency configurations:
    #.project #처음에는 
    
    ### Eclipse Patch ###
    # Spring Boot Tooling
    .sts4-cache/
    
    ### Java ###
    # Compiled class file
    *.class
    
    # Log file
    *.log
    
    # BlueJ files
    *.ctxt
    
    # Mobile Tools for Java (J2ME)
    .mtj.tmp/
    
    # Package Files #
    *.jar
    *.war
    *.nar
    *.ear
    *.zip
    *.tar.gz
    *.rar
    
    # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
    hs_err_pid*
    replay_pid*
    
    # End of https://www.toptal.com/developers/gitignore/api/eclipse,java

git rm -r --cached .
gitignore에 올린다고 바로 적용되지는 않는다
깃에서 이미 추적하고 있던 파일들의 상태는 변하지 않기 때문에 캐시를 삭제해야 한다.

이후 add, commit까지 하면 깃이그노어 파일 내용이 적용된다.

profile
반갑습니다람쥐

0개의 댓글