
Git이란?Git은 분산 버전 관리 시스템(DVCS)으로, 소프트웨어 개발 과정에서 소스 코드의 변경 사항을 추적하고 관리하는 데 사용된다. 또한 Git을 사용하면 여러 개발자가 동시에 작업할 수 있으며, 변경 내용을 효과적으로 병합하고 관리할 수 있다.
GitHub란?GitHub은 Git을 기반으로 한 웹 호스팅 서비스로, 개발자들이 협업하고 소스 코드를 공유할 수 있는 플랫폼을 제공한다. GitHub를 통해 프로젝트를 공개적으로 또는 비공개로 관리할 수 있으며, 이슈 트래킹, 풀 리퀘스트 등의 기능을 활용할 수 있다.
Git Commands 정리git configGit 설치 후 처음으로 해야 하는 일--global 옵션은 처음에만 설정한다.git config --global user.name "John Doe"
git config --global user.email johndoe@example.com
git initGit 저장소로 초기화한다. .git 디렉토리가 생성되며, 이곳에서 Git의 모든 데이터가 관리된다.cd my_project
git init
git cloneGitHub의 원격 저장소를 내 로컬에 복제한다.repository에 있는 파일을 내 로컬의 특정 디렉토리로 가져올 수 있다..를 붙이면 현재 폴더에 바로 파일이 저장된다.# 새 디렉토리에 복제
git clone https://github.com/user/repo.git
# 현재 디렉토리에 복제
git clone https://github.com/user/repo.git .
git status# 파일 "example.txt"를 수정했을 때
git status
# 출력 결과
On branch main
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
modified: example.txt
git addgit add <file>: 특정 파일만 추가git add .: 모든 변경된 파일 추가# 특정 파일 추가
git add example.txt
# 모든 파일 추가
git add .
git commitgit commit: 기본적인 명령어, 이 경우 따로 커밋 메시지 작성 창이 뜬다.git commit -m "message": 커밋 메시지를 포함하여 변경사항 저장git commit --amend: 마지막 커밋 수정# 커밋 메시지와 함께 커밋
git commit -m "Fix typo in example.txt"
# 마지막 커밋 수정
git commit --amend -m "Updated commit message"
git branch, git switchgit branch: 브랜치 생성git switch: 생성된 브랜치로 이동# 브랜치 생성
git branch feature-login
# 생성된 브랜치로 이동
git switch feature-login
git checkoutgit checkout -b feature-login
git mergegit switch main
git merge feature-login
# 출력 결과
Updating abc1234..def5678
Fast-forward
1 file changed, 10 insertions(+)
git remotegit remote add origin https://github.com/user/repo.git
git remote -v
# 출력 결과
origin https://github.com/user/repo.git (fetch)
origin https://github.com/user/repo.git (push)
git pushgit push origin main
# 출력 결과
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Writing objects: 100% (3/3), 456 bytes | 456.00 KiB/s, done.
git loggit log: 상세 커밋 기록 확인git log --oneline: 간단히 커밋 기록 확인git log --oneline
# 출력 결과
abc1234 Fix typo in example.txt
def5678 Add README file
ghijkl9 Initial commit
git restoregit restore example.txt
git resetgit reset <commit-id>: 커밋 되돌림(변경사항 유지)git reset --hard <commit-id>: 커밋 되돌림(변경사항 삭제)git reset --hard abc1234
# 출력 결과
HEAD is now at abc1234 Fix typo in example.txt
git taggit tag <tag-name>: 태그 생성git tag: 태그 목록 확인git tag v1.0
git tag
# 출력 결과
v1.0