My Study
[git] - 사용법
handbefore
2024. 10. 11. 21:38
- 폴더 생성
- 작업 폴더에서 터미널창 열기
- 레포지토리 생성
버전 관리 할 폴더 설정 명령어 (작업 디렉터리)
git init
- 현재 파일 기록
-staging area (전체 / 파일만)
git add .
git add 파일명
-올리고 싶지 않은 파일 (.gitignore 추가)
-repository (스테이지 된 파일들만)
git commit -m "메시지"
- 상태창 열기 (어떤 파일 staging, 수정 ..)
git status
- commit 내역 조회
git log --all --oneline
git log --all --oneline --graph
- commit 전 (최근 commit vs 현재 파일)
git diff
git difftool
git difftool 커밋아이디
- git branch (브랜치 생성: 파일 복사본 만들기)
git branch 브랜치명
- git switch (브랜치 이동)
git switch 브랜치명
git switch main
- git merge (main 브랜치에 합치기)
git merge 브랜치명
-conflict 충돌 해결법
원하는 코드 남기기 -> git add -> git commit
- git restore (파일 복구)
git restore 파일명
git restore --source 커밋아이디 파일명
git restore --staged 파일명
- git revert (commit 취소)
git revert 커밋아이디
git revert HEAD
- git reset
git reset --hard 커밋아이디
git reset --soft 커밋아이디
git reset --mixed 커밋아이디
* 협업시 사용 금지
- 원격 저장소
GitHub: Let’s build from here
GitHub is where over 100 million developers shape the future of software, together. Contribute to the open source community, manage your Git repositories, review code like a pro, track bugs and fea...
github.com
- 레포지토리 생성 (원격 저장소 생성)
- 로컬 저장소 -> 원격 저장소 백업
-로컬 저장소 완성
git init
git branch -M main
git add .
git commit -m "메시지"
-원격 저장소 백업
git push -u 저장소주소 브랜치명
git push -u origin main
- 폴더 생성
- git clone
.을 작성하면 현재 디렉터리가 작업 디렉터리가 됨
git clone 저장소주소 .
git clone 저장소주소
- git pull
git pull 원격저장소주소 브랜치명
- git push
git push origin