Notice
Recent Posts
Recent Comments
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | ||||||
| 2 | 3 | 4 | 5 | 6 | 7 | 8 |
| 9 | 10 | 11 | 12 | 13 | 14 | 15 |
| 16 | 17 | 18 | 19 | 20 | 21 | 22 |
| 23 | 24 | 25 | 26 | 27 | 28 | 29 |
| 30 |
Tags
- 산업AI엑스포
- 구글
- 재량자금
- HTML5
- 스마트농업관리사
- 보이스피싱
- 피지컬ai
- 접근성
- 티스토리
- APEC
- K-뷰티
- 비급여진료가격
- 자바스크립트
- DOM
- 함수
- 국민세정자문단
- ai파운데이션
- 바이오헬스
- WordPress
- 해양안전콘텐츠공모전
- K-푸드
- isds
- bom
- 워드프레스
- 재생에너지허브
- 깃허브
- 프론트엔드
- 모니터링
- 일본어
- 생성형AI
Archives
- Today
- Total
공공기획 스튜디오 퍼블리크
날짜 붙여가며 파일관리하는데 지쳐 이 Git을 하려한다 본문

1. Git 설치와 설정
1.1. 다운로드
- https://www.git-scm.com
1.2. 사용자 설정
// 초기 사용자 설정
$ git config --list // 현재 설정 확인
$ git config --global user.name "개발자 이름"
$ git config --global user.email "개발자 이메일"
// 기본 텍스트 에디터 설정하기
$ git config --global core.editor "에디터명" // 에디터명 code --wait (VS Code), vim, nano, notepad, subl -n -w (Sublime Text)
// 기본 브랜치명 변경
deokh@Luna MINGW64 /d/dev/git-and-github-intro (master)
$ git config --global init.defaultBranch main // main으로 변경
deokh@Luna MINGW64 /d/dev/git-and-github-intro (master)
$ git config --global init.defaultBranch // 변경사항 확인
main
deokh@Luna MINGW64 /d/dev/git-and-github-intro (master)
$
// 기본 브런치명 설정 변경 전에 생성된 git의 기본 브랜치명 변경
deokh@Luna MINGW64 /d/dev/git-and-github-intro (master)
$ git branch -m master main
deokh@Luna MINGW64 /d/dev/git-and-github-intro (main)
$
// 텍스트 파일의 줄바꿈 형식 설정
$ git config --get core.autocrlf // 현재설정 확인
$ git config --get core.autocrlf "설정값"
// 설정값 true 체크아웃시 CRLF 커밋시 LF (Windows 추찬)
input 커밋시 LF 체크아웃시 변환없음 (nacOS, Linux 추천)
false 변환없음.
2. 로컬저장소 사용
2.1. 기본명령어
| 구분 | 기능 | 명령어 | 내용 |
| Basic | 저장소 생성 | git init | 실행한 위치를 Git 저장소로 초기화 |
| 저장소에 파일 추가 | git add 파일명 | 해당 파일을 Git이 추적할 수 있게 저장소에 추가 | |
| 저장소에 수정 내역 제출 | git commit | 변경된 파일을 저장소에 제출 | |
| 저장소 상태 확인 | git status | 현재 저장소의 상태를 출력 | |
| branch | 저장소에 브랜치 추가 | git branch 이름 | 이름의 브랜치 생성 |
| 작업중인 브랜치 변경 | git checkout 브랜치이름 | 현재 작업중인 브랜치 이름을 변경 (cf. checkout 대출하다) | |
| 브랜치 병합 | git merge 브랜치이름 | 현재 작업중인 브랜치에 브랜치이름의 브랜치를 끌어와 병합 |
// 기본적인 흐름
2. git init: 저장소 생성
3. git add, git commit: 프로그램 작성/추가, 1st 커밋
4. git brech, git checkout: 브랜치 생성, 이동
5. git commit -e: 프로그램 수정 후 2nd 커밋
6. git merge: master 브랜치에 병합
2.2. git init 저장소 생성
deokh@Luna MINGW64 /d
$ mkdir dev
deokh@Luna MINGW64 /d
$ cd dev
deokh@Luna MINGW64 /d/dev
$ git init
Initialized empty Git repository in D:/dev/.git/
deokh@Luna MINGW64 /d/dev (master) // naster 브랜치 생성 확인
$
2.3. git add / git commit 첫번째 커밋
| vim 에디터에서 동작 | 키 입력 | 내용 |
| 일반 모드에서 입력 모드로 전환 | i | 현재 위치부터 쓰기 |
| 일반 모드에서 입력 모드로 전환 | o | 다음 줄부터 쓰기 |
| 일반 모드에서 입력 모드로 전환 | a | 한칸 뒤부터 쓰기 |
| 입력/명령 모드에서 일반 모드 전환 | Esc | |
| 일반 모드에서 명령 모드 전환 | : | |
| 명령 모드에서 저장 | :w | 파일 저장 |
| 명령 모드에서 저장 후 종료 | :wq | 저장하고 종료 |
| 명령 모드에서 (저장없이) 종료 | :q! | 저장하지 않고 종료 |
deokh@Luna MINGW64 /d/dev/git-and-github-intro (master)
$ vim hello.py // 파일생성하고 vim 에디터에서 열기
/* hello.py 내용
print ("Hellom, World")
*/
deokh@Luna MINGW64 /d/dev/git-and-github-intro (master)
$ cat hello.py // 파일 내용 보기
print ("hello, World")
deokh@Luna MINGW64 /d/dev/git-and-github-intro (master)
$ python hello.py // 파일 실행
hello, World
deokh@Luna MINGW64 /d/dev/git-and-github-intro (master)
$ git add hello.py // Git에 파일 추가
warning: in the working copy of 'git-and-github-intro/hello.py', LF will be replaced by CRLF the next time Git touches it
deokh@Luna MINGW64 /d/dev/git-and-github-intro (master)
$ git commit
Aborting commit due to empty commit message.
// vim에디터에서 COMMIT_EDITMSG 열림. 커밋 메시지 작성 후 저장하고 닫음. 메시지 첫줄 요약 다음줄부터 세부사항
// 에디터 띄우지 않고 바로 저장하려면 git commit -m "커밋 메시지"
[master (root-commit) 49905ec] Create "hello, World" program
2 files changed, 2 insertions(+)
create mode 100644 GitAndGithubIntro/hello.py
create mode 100644 git-and-github-intro/hello.py
deokh@Luna MINGW64 /d/dev/git-and-github-intro (master)
$
2.4. git branch/ git checkout 새로운 브랜치 생성 및 이동
deokh@Luna MINGW64 /d/dev/git-and-github-intro (master)
$ git branch // 작업중 브랜치 확인
* master
deokh@Luna MINGW64 /d/dev/git-and-github-intro (master)
$ git branch hotfix // 브랜치 생성
deokh@Luna MINGW64 /d/dev/git-and-github-intro (master)
$ git branch
hotfix
* master
// 브랜치 생성과 작업중 브랜치 변경 동시에 git checkout -b 브랜치명
deokh@Luna MINGW64 /d/dev/git-and-github-intro (master)
$ git checkout hotfix // 작업중 브랜치 변경
D GitAndGithubIntro/hello.py
Switched to branch 'hotfix'
deokh@Luna MINGW64 /d/dev/git-and-github-intro (hotfix)
$ git branch
* hotfix
master
deokh@Luna MINGW64 /d/dev/git-and-github-intro (hotfix)
$
2.5. 파일 내용 변경 후 git commit -a 두번째 커밋
deokh@Luna MINGW64 /d/dev/git-and-github-intro (hotfix)
$ vim hello.py
// hello.py에 내용 추가 후 저장 및 닫기
deokh@Luna MINGW64 /d/dev/git-and-github-intro (hotfix)
$ cat hello.py
print ("hello, World")
print ("Branch Test")
deokh@Luna MINGW64 /d/dev/git-and-github-intro (hotfix)
$ python hello.py
hello, World
Branch Test
deokh@Luna MINGW64 /d/dev/git-and-github-intro (hotfix)
$ git commit -a hello.py // add + commit 동시에 명령
warning: in the working copy of 'git-and-github-intro/hello.py', LF will be replaced by CRLF the next time Git touches it
[hotfix a80fd08] Add Phrase.
2 files changed, 1 insertion(+), 1 deletion(-)
delete mode 100644 GitAndGithubIntro/hello.py
deokh@Luna MINGW64 /d/dev/git-and-github-intro (hotfix)
$ git status // 커밋할 파일이 있는지 확인
On branch hotfix
nothing to commit, working tree clean
deokh@Luna MINGW64 /d/dev/git-and-github-intro (hotfix)
$
2.6. git merge 마스터브런치와 병합
deokh@Luna MINGW64 /d/dev/git-and-github-intro (hotfix)
$ git checkout master // 마스터 브랜치로 작업브랜치 변경
Switched to branch 'master'
deokh@Luna MINGW64 /d/dev/git-and-github-intro (master)
$ git status
On branch master
nothing to commit, working tree clean
deokh@Luna MINGW64 /d/dev/git-and-github-intro (master)
$ ls
hello.py
deokh@Luna MINGW64 /d/dev/git-and-github-intro (master)
$ cat hello.py
print ("hello, World")
deokh@Luna MINGW64 /d/dev/git-and-github-intro (master)
$ python hello.py
hello, World
deokh@Luna MINGW64 /d/dev/git-and-github-intro (master)
$ git merge hotfix // 마스터 브랜치에 hotfix를 병합. 즉 hotfix 브랜치 기준으로 마스터 변경
Updating 49905ec..a80fd08
Fast-forward
GitAndGithubIntro/hello.py | 1 -
git-and-github-intro/hello.py | 1 +
2 files changed, 1 insertion(+), 1 deletion(-)
delete mode 100644 GitAndGithubIntro/hello.py
deokh@Luna MINGW64 /d/dev/git-and-github-intro (master)
$
2.7. 각 브랜치의 독립성 확인
deokh@Luna MINGW64 /d/dev/git-and-github-intro (hotfix)
$ vim hello.py
// hello.py에 내용 추가 후 저장 및 닫기
deokh@Luna MINGW64 /d/dev/git-and-github-intro (hotfix)
$ git commit -a hello.py
warning: in the working copy of 'git-and-github-intro/hello.py', LF will be replaced by CRLF the next time Git touches it
[hotfix a6e0ce4] Add Hotfix message
1 file changed, 1 insertion(+)
deokh@Luna MINGW64 /d/dev/git-and-github-intro (hotfix)
$ // hotfix를 master 브랜치에 병합하였더라도 hotfix는 여전히 남아있음.
2.8. 실제 프로젝트에서 발생하는 상황들
- 추적할 필요가 없는 파일을 무시: gitignore
- 여러 브랜치를 병합할 때 발생하는 충돌을 해결
- 커밋한 내역 즉 커밋로그를 살펴보는 법
2.9. gitignore 불필요한 파일 및 폴더 무시
// gitignore 생성 및 확인
deokh@Luna MINGW64 /d/dev (hotfix)
$ touch .gitignore // 파일 생성 및 수정시간 변경
deokh@Luna MINGW64 /d/dev (hotfix)
$ ls
git-and-github-intro/
deokh@Luna MINGW64 /d/dev (hotfix)
$ ls -al
total 8 // 파일이 차지하는 블록(512KB) 수
drwxr-xr-x 1 deokh 197609 0 Sep 8 18:27 ./
drwxr-xr-x 1 deokh 197609 0 Sep 8 11:34 ../
drwxr-xr-x 1 deokh 197609 0 Sep 8 18:13 .git/
-rw-r--r-- 1 deokh 197609 0 Sep 8 18:27 .gitignore
drwxr-xr-x 1 deokh 197609 0 Sep 8 18:12 git-and-github-intro/
deokh@Luna MINGW64 /d/dev (hotfix)
$
// .gitignore 파일 내용 따오기
브라우저에서 https://www.gitignore.io
검색창에 windows, python 등록 후 생성
.gitignore에 붙여넣기
// 다시 git bash에서
deokh@Luna MINGW64 /d/dev/git-and-github-intro (hotfix)
$ git add .gitignore
warning: in the working copy of 'git-and-github-intro/.gitignore', LF will be replaced by CRLF the next time Git touches it
deokh@Luna MINGW64 /d/dev/git-and-github-intro (hotfix)
$ git commit -m "added .gitignore file"
[hotfix d0c2beb] added .gitignore file
1 file changed, 202 insertions(+)
create mode 100644 git-and-github-intro/.gitignore
deokh@Luna MINGW64 /d/dev/git-and-github-intro (hotfix)
$
2.10. 충돌 해결
deokh@Luna MINGW64 /d/dev/git-and-github-intro (hotfix)
$ git checkout master
Switched to branch 'master'
deokh@Luna MINGW64 /d/dev/git-and-github-intro (master)
$ git merge hotfix // hotfix를 master와 합치기
Auto-merging git-and-github-intro/hello.py
CONFLICT (content): Merge conflict in git-and-github-intro/hello.py
Automatic merge failed; fix conflicts and then commit the result. // 충돌이 발생했다고함.
deokh@Luna MINGW64 /d/dev/git-and-github-intro (master|MERGING)
$ cat hello.py
print ("hello, World")
print ("Branch Test")
<<<<<<< HEAD
print ("3rd message")
print ("4nd text")
=======
print ("This is Hotfix")
>>>>>>> hotfix
deokh@Luna MINGW64 /d/dev/git-and-github-intro (master|MERGING)
$ vim hello.py
// vim 에디터에서 다 합치는 걸로 수정함.
deokh@Luna MINGW64 /d/dev/git-and-github-intro (master|MERGING)
$ git commit -a -m "conflict resolved"
[master b88bcdf] conflict resolved
deokh@Luna MINGW64 /d/dev/git-and-github-intro (master)
$
2.11. git log 로그기록 보기
| git log 명령 옵션 | 내용 |
| git log -p | 각 커밋에 적용된 실제 변경 내용을 보여줌. |
| git log --word-diff | diff 명령의 실행결과를 단어 단위로 보여줌. |
| git log --stat | 각 커밋에서 수정된 파일의 통계 정보를 보여줍니다. |
| git log --relative-date | 정확한 시간이 아니라 1일전 1주전 처럼 상대적 시간을 비교하는 형식으로 보여줌. |
| git log --graph | 브랜치 분기와 병합 내역을 아스키 그래프로 보여줌. |
deokh@Luna MINGW64 /d/dev/git-and-github-intro (master)
$ git log --graph // less 라는 페이지뷰어에서 열림.
* commit b88bcdf9ff3fbe661c921cb0c38a37b3ad59b9ef (HEAD -> master)
|\ Merge: c3dbaee d0c2beb
| | Author: Lee Deokho <deokho.lee@hotmail.com>
| | Date: Mon Sep 8 21:51:47 2025 +0900
| |
| | conflict resolved
| |
| * commit d0c2beb5a139ea0e307901a339e8fc681aedaf3b (hotfix)
| | Author: Lee Deokho <deokho.lee@hotmail.com>
| | Date: Mon Sep 8 21:36:44 2025 +0900
| |
| | added .gitignore file
| |
| * commit a6e0ce47e142c342c5f53dd7490feb95e40537dd
| | Author: Lee Deokho <deokho.lee@hotmail.com>
| | Date: Mon Sep 8 18:13:22 2025 +0900
| |
| | Add Hotfix message
| |
* | commit c3dbaeeccb33b3a43604da1963c695becac73e39
|/ Author: Lee Deokho <deokho.lee@hotmail.com>
| Date: Mon Sep 8 18:10:21 2025 +0900
|
| Add Message and Text.
|
* commit a80fd080748e2506f2067f830764a35b733fefeb
| Author: Lee Deokho <deokho.lee@hotmail.com>
| Date: Mon Sep 8 17:33:02 2025 +0900
|
| Add Phrase.
|
* commit 49905ec10038d54f965e3cb8020a7a78157e3cf8
Author: Lee Deokho <deokho.lee@hotmail.com>
Date: Mon Sep 8 14:57:21 2025 +0900
Create "hello, World" program
// 이 페이지 뷰어를 닫으려면 q를 누르면 됨.
deokh@Luna MINGW64 /d/dev/git-and-github-intro (master)
$
3. 원격저장소와 github.com
3.1. github.com 에서 새 리포지토리 생성
- Owner: 협업 환경에서는 협업자 ID가 보이기도 함.
- Repository name: 새로 생성할 원격저장소 이름. 되도록 로컬과 동일한 이름
- Choose visibility: Public/Private
- Add README: 리포지토리 최상단에 위치하여 방문/협업자가 프로젝트를 처음 접할 때 가장 먼저 보게 됨. 사용하도록 설정시 main브랜치를 만들어줘 클론이나 푸쉬가 가능
3.2. Github 원격 저장소의 구조
- Fork: 다른 개발자의 리포지토리를 내 공간에 복제해서 독립적으로 작업할 수 있음.
- Watch: 해당 리포지토리에 새로운 활동이 생길 때 알림 수신
- Star: 즐겨찾기 느낌. 클릭시 Github 프로필의 Starts 목록에 추가
- Description
- Commits
- Branches
- releases: 원격 저장소의 태그 수를 나타냄. 특정 버전에 표식을 주고 싶을 때 사용. 이 표식을 통해 특정버전 다운
- Contributor: 원격 저장소에 커밋 혹은 풀리퀘스트가 받아들여진 사용자 수. 이 저장소가 오픈소스라면 공헌한 사람수
- 상단메뉴
- Code: 리포지토리의 루트로 이동
- Issues: 해당 원격저장소의 주요 이슈사항 기재 후 관리. 저장소 안에서 사용자들 사이의 문제를 논의하는 기능. 게시판 형태
- Pull requests: 풀리퀘스트 전체목록 보여줌. 포크한 저장소를 수정해 다시 원본 저장소에 병합해 달라는 요청을 보내 사용자 사이에 상호작용을 일으킴. 목록마다 댓글형태로 토론가능.
- Wiki: 공유할 정보나 개발문서, 참고자료 등 작성. 리포지토리와 관련된 체계적인 기록을 남김.
- Pulse: 해당 원격저장소의 최근(최대 한달) 변경내역 확인.
- Graphs: 공헌자의 공헌내역. 커밋수 등 해당 저장소의 활동내역을 그래프화
4. 원격저장소와 Git
| 명령어 | 내용 |
| git clone | 원격저장소의 모든 내용을 로컬저장소로 복사 (cf. Fork는 github.com 안에서 원격 저장소를 복사하는 작업) |
| git remote | 로컬저장소를 특정 원격저장소와 연결 |
| git push | 로컬저장소의 내용을 보내거나 로컬저장소의 변경사항을 원격저장소로 보냄. |
| git fetch | 로컬과 원격의 변경사항이 다를 때, 비교/대조하고 git merge 명령어와 함께 최신데이터 반영 및 충돌문제 해결 |
| git pull | git remote 명령을 통해 연결된 원격저장소의 내용을 로컬로 가져오면서 병합 |
4.1. git clone 원격저장소에서 로컬저장소로 가져오기
// 클로닝할 리포지토리 주소
github.com ▶ 해당리포지토리 ▶ Code ▶ Local ▶ HTTPS
// 로컬에서 클로닝
deokh@Luna MINGW64 /d/dev (master)
$ git clone https://github.com/leedeokho76/study.git
Cloning into 'study'...
remote: Enumerating objects: 9, done.
remote: Counting objects: 100% (9/9), done
remote: Compressing objects: 100% (5/5), done.
remote: Total 9 (delta 1), reused 0 (delta 0), pack-reused 0 (from 0)
Receiving objects: 100% (9/9), done.
Resolving deltas: 100% (1/1), done.
deokh@Luna MINGW64 /d/dev/study (main)
$ git status
On branch main
Your branch is up to date with 'origin/main'.
nothing to commit, working tree clean
deokh@Luna MINGW64 /d/dev/study (main)
$
4.2. git remote 로컬저장소와 원격저장소 연결
// 리모팅할 새 리포지토리 생성
github.com ▶ Create new... ▶ New repository ▶ (주의) README 파일 생성 해제
// 로컬에서 리모트
deokh@Luna MINGW64 /d/dev (master)
$ cd git-and-github-intro
deokh@Luna MINGW64 /d/dev/git-and-github-intro (master)
$ git remote add origin https://github.com/leedeokho76/command_hello.git
deokh@Luna MINGW64 /d/dev/git-and-github-intro (master)
$ git remote -v
origin https://github.com/leedeokho76/command_hello.git (fetch)
origin https://github.com/leedeokho76/command_hello.git (push)
deokh@Luna MINGW64 /d/dev/git-and-github-intro (master)
$
4.3. git push 로컬에서 원격저장소로 업로드
// 업로드 할 로컬저장소에서
deokh@Luna MINGW64 /d/dev/git-and-github-intro (main)
$ git push
fatal: The current branch master has no upstream branch.
To push the current branch and set the remote as upstream, use
git push --set-upstream origin main
To have this happen automatically for branches without a tracking
upstream, see 'push.autoSetupRemote' in 'git help config'.
deokh@Luna MINGW64 /d/dev/git-and-github-intro (main)
$ git push --all
Enumerating objects: 10, done.
Counting objects: 100% (10/10), done.
Delta compression using up to 16 threads
Compressing objects: 100% (8/8), done.
Writing objects: 100% (10/10), 2.59 KiB | 1.29 MiB/s, done.
Total 10 (delta 2), reused 0 (delta 0), pack-reused 0 (from 0)
remote: Resolving deltas: 100% (2/2), done.
To https://github.com/leedeokho76/git-and-gihub-intro.git
* [new branch] hotfix -> hotfix
* [new branch] main -> main
deokh@Luna MINGW64 /d/dev/git-and-github-intro (main)
$ git push origin --all
Everything up-to-date
deokh@Luna MINGW64 /d/dev/git-and-github-intro (main)
$ cat >> README.md // README.md 파일에 내용 추가
짓깃과 깃허브 시작의 원격 저장소
deokh@Luna MINGW64 /d/dev/git-and-github-intro (main)
$ git add README.md
warning: in the working copy of 'README.md', LF will be replaced by CRLF the next time Git touches it
deokh@Luna MINGW64 /d/dev/git-and-github-intro (main)
$ git commit -m "add message remote repository once more"
[main 07de653] add message remote repository once more
1 file changed, 1 insertion(+)
deokh@Luna MINGW64 /d/dev/git-and-github-intro (main)
$ git push origin main // main만 원격저장소에 푸시
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 16 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 419 bytes | 59.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 (from 0)
To https://github.com/leedeokho76/git-and-gihub-intro.git
f4c10d4..07de653 main -> main
deokh@Luna MINGW64 /d/dev/git-and-github-intro (main)
$ cat hello.py
print ("hello, World")
print ("Branch Test")
print ("3rd message")
print ("4nd text")
print ("This is Hotfix")
print ("5th message")
deokh@Luna MINGW64 /d/dev/git-and-github-intro (hotfix)
$ git checkout main
Switched to branch 'main'
deokh@Luna MINGW64 /d/dev/git-and-github-intro (main)
$ ls
README.md hello.py
deokh@Luna MINGW64 /d/dev/git-and-github-intro (main)
$ cat >> hello.py
내용을 추가함. adding content.
deokh@Luna MINGW64 /d/dev/git-and-github-intro (main)
$ cat hello.py
print ("hello, World")
print ("Branch Test")
print ("3rd message")
print ("4nd text")
print ("This is Hotfix")
print ("5th message")
내용을 추가함. adding content.
deokh@Luna MINGW64 /d/dev/git-and-github-intro (main)
$ git add hello.py
warning: in the working copy of 'hello.py', LF will be replaced by CRLF the next time Git touches it
deokh@Luna MINGW64 /d/dev/git-and-github-intro (main)
$ git commit -m "또 추가해봤음.
> "
[main 46e6395] 또 추가해봤음.
1 file changed, 1 insertion(+)
deokh@Luna MINGW64 /d/dev/git-and-github-intro (main)
$ git push origin main
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 16 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 347 bytes | 347.00 KiB/s, done.
Total 3 (delta 2), reused 0 (delta 0), pack-reused 0 (from 0)
remote: Resolving deltas: 100% (2/2), completed with 2 local objects.
To https://github.com/leedeokho76/git-and-gihub-intro.git
07de653..46e6395 main -> main
deokh@Luna MINGW64 /d/dev/git-and-github-intro (main)
$ git checkout hotfix // hotfix로 전환
Switched to branch 'hotfix'
deokh@Luna MINGW64 /d/dev/git-and-github-intro (hotfix)
$ git merge main // hotfix에 main을 반영
Updating f4c10d4..46e6395
Fast-forward
README.md | 1 +
hello.py | 1 +
2 files changed, 2 insertions(+)
deokh@Luna MINGW64 /d/dev/git-and-github-intro (hotfix)
$ git checkout main
Switched to branch 'main'
deokh@Luna MINGW64 /d/dev/git-and-github-intro (main)
$ git push origin hotfix
Total 0 (delta 0), reused 0 (delta 0), pack-reused 0 (from 0)
To https://github.com/leedeokho76/git-and-gihub-intro.git
f4c10d4..46e6395 hotfix -> hotfix
deokh@Luna MINGW64 /d/dev/git-and-github-intro (main)
$ git status
On branch main
nothing to commit, working tree clean
deokh@Luna MINGW64 /d/dev/git-and-github-intro (main)
$ git checkout hotfix
Switched to branch 'hotfix'
deokh@Luna MINGW64 /d/dev/git-and-github-intro (hotfix)
$ git push origin hotfix
Everything up-to-date
deokh@Luna MINGW64 /d/dev/git-and-github-intro (hotfix)
$
4.4. git fetch / git pull 로컬과 원격 저장소 동기화
// 로컬과 원격 저장소에서 각각 변경 내용이 있는 상태에서 fetch
deokh@Luna MINGW64 /d/dev/git-and-github-intro (main)
$ git status
On branch main
nothing to commit, working tree clean
deokh@Luna MINGW64 /d/dev/git-and-github-intro (main)
$ git push origin main
To https://github.com/leedeokho76/git-and-gihub-intro.git
! [rejected] main -> main (fetch first)
error: failed to push some refs to 'https://github.com/leedeokho76/git-and-gihub-intro.git'
hint: Updates were rejected because the remote contains work that you do not
hint: have locally. This is usually caused by another repository pushing to
hint: the same ref. If you want to integrate the remote changes, use
hint: 'git pull' before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
deokh@Luna MINGW64 /d/dev/git-and-github-intro (main)
$ git fetch
remote: Enumerating objects: 5, done.
remote: Counting objects: 100% (5/5), done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 3 (delta 2), reused 0 (delta 0), pack-reused 0 (from 0)
Unpacking objects: 100% (3/3), 1012 bytes | 33.00 KiB/s, done.
From https://github.com/leedeokho76/git-and-gihub-intro
46e6395..173865c main -> origin/main
deokh@Luna MINGW64 /d/dev/git-and-github-intro (main)
$ git branch -a
hotfix
* main
remotes/origin/HEAD -> origin/main
remotes/origin/hotfix
remotes/origin/main
deokh@Luna MINGW64 /d/dev/git-and-github-intro (main)
$ git merge ^C
deokh@Luna MINGW64 /d/dev/git-and-github-intro (main)
$ git merge origin/main
Auto-merging hello.py
CONFLICT (content): Merge conflict in hello.py
Automatic merge failed; fix conflicts and then commit the result.
deokh@Luna MINGW64 /d/dev/git-and-github-intro (main|MERGING)
$ git diff
diff --cc hello.py
index ce743c2,8aa4fa5..0000000
--- a/hello.py
+++ b/hello.py
@@@ -1,4 -1,5 +1,9 @@@
++<<<<<<< HEAD
+// 이건 로컬에서 입력한 주석
++=======
+ // 깃과 것허브 테스트를 위한 테스트 파일
+ // 아직도 테스트 중
++>>>>>>> origin/main
print ("hello, World")
print ("Branch Test")
deokh@Luna MINGW64 /d/dev/git-and-github-intro (main|MERGING)
$ vim hello.py
deokh@Luna MINGW64 /d/dev/git-and-github-intro (main|MERGING)
$ git commit -a -m "로컬과 원격의 주석 병합"
[main 413e2ad] 로컬과 원격의 주석 병합
deokh@Luna MINGW64 /d/dev/git-and-github-intro (main)
$ git status
On branch main
nothing to commit, working tree clean
deokh@Luna MINGW64 /d/dev/git-and-github-intro (main)
$ git push origin main
Enumerating objects: 10, done.
Counting objects: 100% (10/10), done.
Delta compression using up to 16 threads
Compressing objects: 100% (6/6), done.
Writing objects: 100% (6/6), 637 bytes | 637.00 KiB/s, done.
Total 6 (delta 4), reused 0 (delta 0), pack-reused 0 (from 0)
remote: Resolving deltas: 100% (4/4), completed with 2 local objects.
To https://github.com/leedeokho76/git-and-gihub-intro.git
173865c..413e2ad main -> main
deokh@Luna MINGW64 /d/dev/git-and-github-intro (main)
$
5. 기타 Git 명령어
| 명령어 | 내용 |
| git tag | 커밋을 참조하기 쉽도록 태그 붙임. |
| git commit --amend | 같은 브랜치 상의 최종 커밋을 취소하고 새로운 내용을 추가하거나 설명을 덧붙인 커밋함. |
| git revert | 이전 생성한 커밋 삭제. 단 특정 커밋의 내용을 지우는 새로운 커밋 생성하여 지운 내역을 협력자 인지 |
| git reset | 특정 커밋을 버리고 이전의 특정 버전으로 되돌림. 단 revert와 다르게 지운 커밋 내역을 남기지 않음. |
| git checkout HEAD --filename | 아직 커밋하지 않은 변경 내역을 취소 |
| git rebase | git merge처럼 병합. 브랜치가 많을 경우 브랜치 이력을 확인하면서 변경 |
| git rebase -i | 서로 다른 두개의 커밋 내역을 합침. |
6. Github.com에서 정적 웹사이트 만들기
6.1. 리포지토리 생성
- 웹주소는 사용자명.github.io/리포지토리 형식이 됨.
6.2. 페이지 주소 발행
- Settings - Pages - Branch 에서 None을 main으로 변경한 후 Save
[참고자료]
- 윤웅식, (만들면서 배우는) Git GitHub 입문: 세상의 모든 개발 코드를 공유하고 관리하는 소셜 코딩, 한빛미디어 (2016)
- https://www.git-scm.com/book/v2
- https://www.git-scm.com/book/ko/v2/시작하기-Git-설치
- https://www.git-scm.com/book/ko/v2/Git-브랜치-브랜치와-Merge의-기초
- (Reference) https://www.git-scm.com/docs/gitignore
- (GitHub Docs) https://guides.github.com
- (GitHub Desktop) https://windows.github.com
- (Programmer's Q&A) https://www.stackoverflow.com
- (GUI Clients) https://git-scm.com/downloads/guis
'Reference' 카테고리의 다른 글
| 인체생리학 요약 (0) | 2025.02.17 |
|---|---|
| 영양과 건강 요약 (2) | 2025.02.17 |
| MS워드에서 일본어 활용 (0) | 2025.02.03 |
| 컴퓨터 키보드 이야기 (0) | 2024.09.18 |
| JavaScript 개발 환경을 고려한 VSCode 설정 (0) | 2024.08.16 |