7. git config
• 원하는 방법을 선택하여 설정
$> git config —-system (/etc/gitconfig)
$> git config —-global (~/.gitconfig)
$> git config —-local (.git/config)
$> git config —-global user.name “insanehong”
$> git config —-global user.email “insanehong@gmail.com”
8. git config
• 자주 사용하게될 설정은 global 로 설정
//commit author 정보로 사용될 author name
$> git config —-global user.name “your name”
//commit author 정보로 사용될 author email
$> git config —-global user.email “your email”
//git 이 사용할 기본 text editor 설정
$> git config --global core.editor emacs
//git이 사용할 기본 diff tool 설정
$> git config --global diff.tool vimdiff //diff tool
9. git config
• config 정보 확인
$> git config —-list //모든 설정값
$> git config user.name //지정한 설정값
10. git management step
• Working Directory : 작업공간
• Staging Area
- 커밋 가능한 파일들의 정보를 저장
- .git/index
• Object Database : Commit Object 저장소
- Commit Object 저장소
- .git/objects
12. git init
• local 에서 git 저장소를 만드는 2가지 방법
$> git init //Working Directory 를 갖는 새로운 저장소를 추가
$> git init —bare //Working Directory 가 없는 저장소
$> git clone <repo_url>//remote 저장소에서 받아오는 경우
13. git status
• working directory 의 파일의 상태 조회
$> git status //git init 직후 실행해보면
On branch master
Initial commit
nothing to commit (create/copy files and use "git add" to
track)
14. git은 status
• Untracked : git이 관리하고 있지 않음
• Tracked : git이 관리중
• Unmodified : 마지막 commit 후 수정되 않음
$> git init —-bare
• modified : 마지막 commit 이후 수정됨
• Staged : 수정내용을 commit 할 수 있음
16. git status
• 새로운 파일을 만들어서 다시 확인
$> echo hello world >> README.md
//hello world 라는 내용을 가진 README.md 파일 생성
$> git status
On branch master
Initial commit
Untracked files:
(use "git add <file>..." to include in what will be committed)
README.md
nothing added to commit but untracked files present
(use "git add" to track)
17. git add
• Untracked file 을 Staged 로 만들기
$> git add README.md
$> git status
On branch master
Initial commit
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: README.md
18. git commit
• Staged 파일을 Tracked/Unmodified 파일로 만들기
//여러줄의 메세지를 작성할때
$> git commit
//한줄정도의 간단한 메세지를 작성할때
$> git commit -m “add new file: README.md”
[master (root-commit) 9de70a9] add new file: README.md
1 file changed, 1 insertion(+)
create mode 100644 README.md
21. git show
• commit 의 상세 정보확인
// 일반적으로 별도의 타겟을 정하지 않으면 HEAD가 가리키는 commit
$> git show
// 특정 commit의 상세 정보 조회
$> git show <commit>
// 특정 branch 가 가리키는 commit의 상세 정보 조회
$> git show <branch_name>
// HEAD 를 기준을 상위 여러개의 commit 상세정보 조회
$> git show HEAD~{number>
22. git push
• 원격 저장소로 코드 보내기
$> git push <remote_name> <current_branch_name>
// remote 를 origin 으로 등록했을 경우
// branch 를 변경한적 없다면 master 가 default
$> git push origin master
23. git clone
• 원격 저장소 코드 받아오기
$> git clone <path>
// local 에 있는 —-bare 저장소도 가능
$> git clone ./local-remote.git/
25. git tracked 상태 파일 관리 tip
• 파일의 변경정보를 add 없이도 staged 상태로 변경
$> git rm <file_name> //파일삭제
$> git mv <origin_file> <target> //파일 이름 변경 혹은 이동
26. git working directory 관리 tip
• staged 상태 관리
$> git add . //변경 된 파일 모두 staged 상태로 추가
$> git add -u //변경된것과 삭제된 파일만 staged 상태로 추가
$> git add -p //hunk 단위로 관리가능
27. git working directory 관리 tip
• 작업 파일 관리
$> git checkout <file_name> //변경중이던 파일 Unmodified 상태로 되돌리기
$> git rm --cached <file_name> //Untracked 상태로 변경
//Staged 상태의 파일을 Modified 상태로 변경
$> git reset <file_name>
28. git HEAD/branch 관리 tip
//HEAD 와 branch 가 특정 커밋을 바라보도록 수정
$> git reset —-hard <commit>|<branch_name>
//HEAD 와 branch 를 현재 커밋 시점으로 이전 커밋을 바라보도록 수정
$> git reset —-hard HEAD^
//HEAD 와 branch 를 현재 커밋 시점으로 특정 시점의 커밋을 바라보도록 수정
$> git reset —-hard HEAD~{number}
—-hard 옵션을 사용하지 않으면 변경내역이 있는 파일들은
working directory에 modified 상태로 유지
29. git commit 관리 tip
//새로운 파일을 추가하거나 Tracked 파일을 수정하지 않고 메세지만 변경하
고 싶은 경우에는 도 git commit —-amend 를 바로 사용가능
$> git commit —-amend
$> git commit -a //staged 상태 건너뛰고 바로 commit
$> git commit -v //commit editor 에 diff 정보를 추가
30. git diff 확인
$ git diff //Unstaged 상태의 diff 확인
$> git diff —-cached //Staged 상태의 diff 확인
31. git commit 관리 tip
주의!!!
root commit은 —-amend 옵션을 제외하고 이후 변경불가
.gitignore 파일을 추가후 initialize commit 추천
32. git push tip
//현재 branch 변경이력을 remote에 존재하는 다른이름의 branch에 반영
시키거나 새로운 branch 를 만들면서 변경이력을 올리는 방법
$> git push <remote> <target_branch>:<current_branch>
//현재 branch 의 변경이력을 remote 의 branch에 강제로 적용시키기
$> git push —-force|-f <remote_name> <branch_name>
33. git commit
주의!!!
push —-force 를 해버린 경우
다른 팀원들이 고통의 나날을 보낼수 있습니다.
강제 push 전에는 팀원들과 미리 협의하길 추천.
34. git clone tip
// clone 받을 directory 명을 지정
$> git clone <repo_path> <directory_name>
// remote 에서 특정 branch 를 지정해서 clone 받고 싶은 경우
$> git clone <repo_path> -b <branch_name>
35. 언젠가는 꼭 써보게 되거나 찾게 될 command 들
• 지금은 이런게 있다는것만 알아도
$> git reflog //gc 가 일어나기 전까지 과거 이력 조회
$> git cherry-pick <commit> //커밋 가져오기
$> git stash //modified 파일들의 변경내역을 임시로 저장
$> git tag //version 관리 v0.0.1
37. 본 자료는 14.11.1 KGUG(Korea Git User Group) 주최 대학생 대상 Git 교육인
“Getting Started with git” 에서 발표된 “Git Basic Commands” 의 발표내용을 담고 있습니다.
본 자료에 사용 된 이미지들은 Creative Common License 를 따르고 있습니다.
사용된 이미지의 출처는 해당 이미지 하단에 기제 되어 있습니다.
본 자료에 대한 수정 배포는 허가 하지 않습니다.
본자료를 공유하실 경우 원본에 대한 임의 수정을 금하며 저작자를 반드시 명시해 주시기 바랍니다.
twitter : @insanehong
email : insanehong@gmail.com