본문 바로가기
프로그래밍/Git

[Git] 시작하기

by 코딩중독 2023. 11. 9.

git 설정 범위와 설정 파일

설정 범위

  • 시스템(system) : 해당 컴퓨터의 모든 저장소와 사용자에 적용 (거의 사용되지 않음)
  • 전역(global) : 해당 컴퓨터의 현재 사용자의 모든 저장소에 적용
  • 지역(local) : 특정 저장소에 적용

설정 파일 (위치)

  • 전역(global) : 운영체제의 사용자 폴더의 .gitconfig

전역 설정 파일

 

  • 지역(local) : 저장소 폴더의 .git/config

지역 설정 파일

 


git 명령어

설정 추가하기

git config <이름> <값>
git config --<범위> <이름> <값>

// 사용법
git config user.name "myname"
git config --global user.email "my_email@kakao.com"

 

설정된 옵션 확인하기

git config <이름>
git config --list

// 사용법
git config user.name
git config user.email
git config --list

 

설정된 옵션 삭제하기

git config --unset <이름>
git config --<범위> --unset <이름>

// 사용법
git config --unset user.name
git config --unset --global user.email

 

git add

파일을 스테이지 영역에 추가, add 명령을 받지 않은(포함되지 않은) 파일은 commit 불가

git add <file> <file>
git add -A

// 사용법
git add a.txt b.txt	// a.txt 와 b.txt 추가
git add -A

 

git commit

변경된 내용을 저장, 변경된 내용에 대한 스냅샷을 생성

git commit -m "message"
git commit <file> -m "message"

// 사용법
git commit -m "fitst commit"	// "first commit" 이라는 메시지로 스테이지에 포함된 모든 파일 commit
git commit c.txt -m "c file commit"	// c.txt라는 파일에 대해 "c file commit" 라는 메시지로 commit

 

git status

저장소의 관리 상태 확인하기

git status

 

생성/추가된 파일이 있다면 add 명령어를 사용하여 포함되어야 commit 이 가능하다는 안내 메시지 출력됨

(use "git add <file>..." to include in what will be committed)

 

add 명령어를 통해 포함된 파일 있다면 제외할 수 있는 명령어에 대한 안내 매시지 출력됨

(use "git restore --staged <file>..." to unstage)

 

git push

commit 된 파일을 원격 저장소에 업로드

git remote add origin <원격 저장소>
git push -u origin main

 

git clone

github에서 repository를 컴퓨터에 처음 받아올 때 (모든 버전을 포함)

git clone <원격 저장소>
git clone <원격 저장소> <로컬 위치>

// 로컬 위치 생략 가능

 

git branch

git branch <브랜치명>	// 브랜치 생성
git checkout <브랜치명>	// 브랜치로 이동
git branch	// 브랜치 목록 확인
git push origin <브랜치명>	// 브랜치를 원격 저장소에 업로드

'프로그래밍 > Git' 카테고리의 다른 글

[Github] Issues, pull requests 사용법  (0) 2024.02.09