MEMO
[git] 자주 쓰는 git 명령어 정리
NPC
2021. 7. 30. 21:55
1. git init
$ git init
Initialized empty Git repository in C:[path]
현재 디렉터리 아래에 .git 디렉터리를 만들고, 여기에 git 저장소 초기화하기
2. git status
$ git status
On branch master
No commits yet
Untracked files:
(use "git add <file>..." to include in what will be committed)
[files]
nothing added to commit but untracked files present (use "git add" to track)
현재 git 저장소 상태 확인하기
3. git add
$ git add .
커밋할 파일 추가하기
4. git commit
$ git commit -m "commit-name"
[master (root-commit) ______] commit-name
__ files changed, ____ insertions(+)
create mode ______ [file-name]
추가한 파일 커밋하기
-m "commit-name": 커밋명 설정하기
5. git branch
$ git branch -M main
git 브랜치 main으로 설정하기
6. git remote
$ git remote add origin https://github.com/[user-name]/[repository-name].git
앞으로 현재 디렉토리에서는 [repository-name] 레파지토리에 자동으로 add 되도록 설정하기
$ git remote remove origin
기존 리모트 레파지토리 삭제하기
7. git branch
$ git branch
* main
현재 브랜치 확인하기
8. git reset
$git reset 커밋ID
커밋 되돌리기
$git reset --hard 커밋ID
모든 작업 상태 내 변경 사항을 버림
$git reset --soft 커밋ID
모든 로컬 변경사항을 유지
$git reset --mixed 커밋ID
작업 상태는 그대로 두지만 인덱스는 리셋
9. git clone
$git clone 레파지토리url
레파지토리 소스 가져오기
10. git config
$git config --global user.name "이름"
사용자 이름, 이메일 설정
--global: 전체 적용
user.name: 이름 / user.email: 이메일
계속 추가될 예정...
(최근 업데이트: 2024.09.18)