SERVER/Git

#1 - Git 시작하기

완자✨ 2021. 9. 19. 21:08

Git 시작하기

Git 환경 설정

  1. 바탕화면 git bash 실행
  2. git config --list
  3. git config user.name
  4. git config --global user.name
  5. git config user.email
  6. git config --global user.email
  7. git config 한눈에 보기
  8. cat ~/.gitconfig

--global 이 들어가면 컴퓨터 전역에 설정한다. 반복 수행할 필요가 없어진다.

로컬 저장소 만들기

  1. cd "work-dir"
  2. git init
  3. .gitignore 파일 작성
  4. git add --all  // git add <file명> 또는 git add .
  5. git commit -m "first commit message"
  6. git remote add origin <git-remote-url>
  7. git push -u origin master
  8. git log
  9. git status # staging 상태 확인

(참고) GibHub RemoteURL 패턴 : https://github.com/<사용자이름>/<저장소명>.git

 

원격 서버에 push 할 때 충돌이 발생한 경우 6번 명령어를 git push -fu origin master로 입력합니다. -fu : 충돌이 나도 무시하고 보낸다라는 의미.

 

 

주의할 점

  • 팀원이 코드를 수정하거나 커밋했을 때 서버 레파지토리를 먼저 pull로 코드를 동기화해야 합니다. 그다음에 push 해야 reject가 발생하지 않습니다.

git clone & pull 하는 방법

GitHub에 만든 repo와 클론 하기

  1. git clone "github-remote-url"

git pull : 서버의 최신 소스를 다운로드하기

  1. git pull 
  2. touch aaa.txt
  3. git add --all
  4. git commit -am “message”
  5. git push

(참고: 서버와 연결된 repo 끊기): git remote rm origin

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

Git 사용자 인증 오류  (0) 2021.09.28
# 4 - Git 실무 - with VSCode  (0) 2021.09.24
# 3 - Git Branch / merge  (0) 2021.09.21
[Git] Reset & Revert / conflict & merge  (0) 2021.09.20
[Git] .gitignore 파일  (0) 2021.09.19