본문 바로가기

혼자하는 공부

[Git] Git 명령어 모음

- Git 초기 설정

git config --global user.name “username”

git config --global user.email “email”

 

-현재 디렉토리를 Git 저장소로 지정

git init

 

-상태 보기

git status

 

-인덱스에 파일 추가
-특정 파일 추가

git add 파일

-모든 파일 추가

git add .



-Commit을 통해 저장소에 기록

git commit -m ‘comments’

 

-변경사항 확인

git log

 

-원격 저장소와 연결

public repo

git remote add origin http://github.com/username/레포지토.git

 

private repo

git remote add origin https://personal토큰@github.com/username/레포지토.git

 

-브랜치 생성

git branch -M main

 

-Git 푸시

git push -u origin main
  • 패스워드 입력하라고 뜰 시 토큰 입력
  • personal token 입력

 

-Clone 생성

public repo

git clone http://github.com/username/레포지토.git

 

private repo

git clone https://personal토큰@github.com/username/레포지토.git

 

-pull, fetch

pull과 fetch의 차이는 가져온 소스를 merge 하느냐 안하느냐의 차이.

pull은 원격 저장소의 소스를 가져오고 해당 소스가 현재 내 소스보다 더 최신 버전이라면 지금의 버전을 해당 소스에 맞춰 올림 merge 사용

fetch는 소스만 가져올 뿐 merge 하지 않음.

 

  • fetch
git fetch origin
  • pull
git pull origin main