Git Basic Commands #Getting started with git insanehong@KGUG
insanehong.talk.start(“Hi! Bro!”) NAVER / NAVER Labs 웹 개발자 / KGUG 운영진 Twitter: @insanehong Email : insanehong@gmail.com
Command Line Interface 로 교육을 하는 이유
Command Line Interface 와 친해지면
기초적인 내용이니 포기하지 마시고 잘 따라와 주세요
git config • 유닉스 계열 $> /etc/gitconfig $> ~/.gitconfig $> .git/config $> git config —-global user.name “insanehong” $HOME/.gitconfig C:Documents and Settings$USER/ C:Users$USER $> git config —-global user.email “insanehong@gmail.com” • 윈도우
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”
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
git config • config 정보 확인 $> git config —-list //모든 설정값 $> git config user.name //지정한 설정값
git management step • Working Directory : 작업공간 • Staging Area - 커밋 가능한 파일들의 정보를 저장 - .git/index • Object Database : Commit Object 저장소 - Commit Object 저장소 - .git/objects
git management step
git init • local 에서 git 저장소를 만드는 2가지 방법 $> git init //Working Directory 를 갖는 새로운 저장소를 추가 $> git init —bare //Working Directory 가 없는 저장소 $> git clone <repo_url>//remote 저장소에서 받아오는 경우
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)
git은 status • Untracked : git이 관리하고 있지 않음 • Tracked : git이 관리중 • Unmodified : 마지막 commit 후 수정되 않음 $> git init —-bare • modified : 마지막 commit 이후 수정됨 • Staged : 수정내용을 commit 할 수 있음
git은 status $> git init —-bare
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)
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
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
git log • commit 이력 조회 // commit 이력 조회 $> git log // 이쁘게 꾸밀수 있음. alias 로 등록된 log format $> git log --graph --format=format:'%C(bold blue)%h %C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green) (%ar)%C(reset)%C(bold yellow)%d%C(reset)%n'' %C(white)%s%C(reset) %C(bold white)— %an%C(reset)' -- abbrev-commit
git log • commit 이력 조회 // commit 이력 조회 $> git log // 이쁘게 꾸밀수 있음. alias 로 등록된 log format $> git log --graph --format=format:'%C(bold blue)%h %C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green) (%ar)%C(reset)%C(bold yellow)%d%C(reset)%n'' %C(white)%s%C(reset) %C(bold white)— %an%C(reset)' -- abbrev-commit
git show • commit 의 상세 정보확인 // 일반적으로 별도의 타겟을 정하지 않으면 HEAD가 가리키는 commit $> git show // 특정 commit의 상세 정보 조회 $> git show <commit> // 특정 branch 가 가리키는 commit의 상세 정보 조회 $> git show <branch_name> // HEAD 를 기준을 상위 여러개의 commit 상세정보 조회 $> git show HEAD~{number>
git push • 원격 저장소로 코드 보내기 $> git push <remote_name> <current_branch_name> // remote 를 origin 으로 등록했을 경우 // branch 를 변경한적 없다면 master 가 default $> git push origin master
git clone • 원격 저장소 코드 받아오기 $> git clone <path> // local 에 있는 —-bare 저장소도 가능 $> git clone ./local-remote.git/
알아두면 유용한 Git Tip
git tracked 상태 파일 관리 tip • 파일의 변경정보를 add 없이도 staged 상태로 변경 $> git rm <file_name> //파일삭제 $> git mv <origin_file> <target> //파일 이름 변경 혹은 이동
git working directory 관리 tip • staged 상태 관리 $> git add . //변경 된 파일 모두 staged 상태로 추가 $> git add -u //변경된것과 삭제된 파일만 staged 상태로 추가 $> git add -p //hunk 단위로 관리가능
git working directory 관리 tip • 작업 파일 관리 $> git checkout <file_name> //변경중이던 파일 Unmodified 상태로 되돌리기 $> git rm --cached <file_name> //Untracked 상태로 변경 //Staged 상태의 파일을 Modified 상태로 변경 $> git reset <file_name>
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 상태로 유지
git commit 관리 tip //새로운 파일을 추가하거나 Tracked 파일을 수정하지 않고 메세지만 변경하 고 싶은 경우에는 도 git commit —-amend 를 바로 사용가능 $> git commit —-amend $> git commit -a //staged 상태 건너뛰고 바로 commit $> git commit -v //commit editor 에 diff 정보를 추가
git diff 확인 $ git diff //Unstaged 상태의 diff 확인 $> git diff —-cached //Staged 상태의 diff 확인
git commit 관리 tip 주의!!! root commit은 —-amend 옵션을 제외하고 이후 변경불가 .gitignore 파일을 추가후 initialize commit 추천
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>
git commit 주의!!! push —-force 를 해버린 경우 다른 팀원들이 고통의 나날을 보낼수 있습니다. 강제 push 전에는 팀원들과 미리 협의하길 추천.
git clone tip // clone 받을 directory 명을 지정 $> git clone <repo_path> <directory_name> // remote 에서 특정 branch 를 지정해서 clone 받고 싶은 경우 $> git clone <repo_path> -b <branch_name>
언젠가는 꼭 써보게 되거나 찾게 될 command 들 • 지금은 이런게 있다는것만 알아도 $> git reflog //gc 가 일어나기 전까지 과거 이력 조회 $> git cherry-pick <commit> //커밋 가져오기 $> git stash //modified 파일들의 변경내역을 임시로 저장 $> git tag //version 관리 v0.0.1
insanehong.talk.end(“Thanks. Bye!!”) http://www.flickr.com/photos/adulau/8442476626/
본 자료는 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

git-basic-commands

  • 1.
    Git Basic Commands #Getting started with git insanehong@KGUG
  • 2.
    insanehong.talk.start(“Hi! Bro!”) NAVER/ NAVER Labs 웹 개발자 / KGUG 운영진 Twitter: @insanehong Email : insanehong@gmail.com
  • 3.
    Command Line Interface로 교육을 하는 이유
  • 4.
    Command Line Interface와 친해지면
  • 5.
    기초적인 내용이니 포기하지마시고 잘 따라와 주세요
  • 6.
    git config •유닉스 계열 $> /etc/gitconfig $> ~/.gitconfig $> .git/config $> git config —-global user.name “insanehong” $HOME/.gitconfig C:Documents and Settings$USER/ C:Users$USER $> git config —-global user.email “insanehong@gmail.com” • 윈도우
  • 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
  • 11.
  • 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 할 수 있음
  • 15.
    git은 status $>git init —-bare
  • 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
  • 19.
    git log •commit 이력 조회 // commit 이력 조회 $> git log // 이쁘게 꾸밀수 있음. alias 로 등록된 log format $> git log --graph --format=format:'%C(bold blue)%h %C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green) (%ar)%C(reset)%C(bold yellow)%d%C(reset)%n'' %C(white)%s%C(reset) %C(bold white)— %an%C(reset)' -- abbrev-commit
  • 20.
    git log •commit 이력 조회 // commit 이력 조회 $> git log // 이쁘게 꾸밀수 있음. alias 로 등록된 log format $> git log --graph --format=format:'%C(bold blue)%h %C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green) (%ar)%C(reset)%C(bold yellow)%d%C(reset)%n'' %C(white)%s%C(reset) %C(bold white)— %an%C(reset)' -- abbrev-commit
  • 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/
  • 24.
  • 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
  • 36.
  • 37.
    본 자료는 14.11.1KGUG(Korea Git User Group) 주최 대학생 대상 Git 교육인 “Getting Started with git” 에서 발표된 “Git Basic Commands” 의 발표내용을 담고 있습니다. 본 자료에 사용 된 이미지들은 Creative Common License 를 따르고 있습니다. 사용된 이미지의 출처는 해당 이미지 하단에 기제 되어 있습니다. 본 자료에 대한 수정 배포는 허가 하지 않습니다. 본자료를 공유하실 경우 원본에 대한 임의 수정을 금하며 저작자를 반드시 명시해 주시기 바랍니다. twitter : @insanehong email : insanehong@gmail.com