{"id":19002581,"url":"https://github.com/jeonghwan-kim/git-usage","last_synced_at":"2025-04-16T22:31:46.306Z","repository":{"id":41190325,"uuid":"69233085","full_name":"jeonghwan-kim/git-usage","owner":"jeonghwan-kim","description":"자주 사용하는 깃 명령어 모음 ","archived":false,"fork":false,"pushed_at":"2022-06-03T11:31:23.000Z","size":6,"stargazers_count":322,"open_issues_count":1,"forks_count":136,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-11-08T18:15:35.927Z","etag":null,"topics":["git","tip","tips"],"latest_commit_sha":null,"homepage":"http://jeonghwan-kim.github.io/dev/2020/02/10/git-usage.html","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jeonghwan-kim.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-09-26T09:12:26.000Z","updated_at":"2024-11-02T08:57:03.000Z","dependencies_parsed_at":"2022-09-12T08:12:03.590Z","dependency_job_id":null,"html_url":"https://github.com/jeonghwan-kim/git-usage","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeonghwan-kim%2Fgit-usage","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeonghwan-kim%2Fgit-usage/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeonghwan-kim%2Fgit-usage/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeonghwan-kim%2Fgit-usage/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jeonghwan-kim","download_url":"https://codeload.github.com/jeonghwan-kim/git-usage/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249283021,"owners_count":21243661,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["git","tip","tips"],"created_at":"2024-11-08T18:15:27.570Z","updated_at":"2025-04-16T22:31:46.299Z","avatar_url":"https://github.com/jeonghwan-kim.png","language":null,"readme":"# git-usage\n자주 사용하는 깃 명령어 모음 \n\n\n## 구조 \n\n코드는 아래 세 단계에 걸쳐 저장된다.\n\n스테이징 -\u003e 커밋 -\u003e 원격저장소\n\n1. git add {파일명} 으로 파일을 스테이징 상태에 넣는다.\n2. git commit 으로 스테이징 상태에 있는 모든 변경사항을 커밋한다. 여기까지가 로컬에서의 작업\n3. git push 로 커밋된 저장소를 원격 저장소로 밀어넣는다.\n\n\n## 기본 명령어\n\n저장소 생성\n\n```\ngit init\n```\n\n원격 저장소로부터 복제 \n\n```\ngit clone {url}\n```\n\n변경 사항 체크\n\n```\ngit status // \n```\n\n특정 파일 스테이징\n\n```\ngit add {파일명} \n```\n\n변경된 모든 파일 스테이징\n\n```\ngit add * \n```\n\n커밋\n\n```\ngit commit -m “{변경 내용}” \n```\n\n원격으로 보내기\n\n```\ngit push origin master \n```\n\n원격저장소 추가\n\n```\ngit remote add origin {원격서버주소} \n```\n\n참고 페이지\n\n- download(osx): http://code.google.com/p/git-osx-installer/downloads/list\n- download(windows): http://git-scm.com/download/win\n- 설치 메뉴얼: http://blog.outsider.ne.kr/389\n- 사용 메뉴얼:http://dogfeet.github.io/articles/2012/how-to-github.html\n- git 간편 안내서: http://rogerdudler.github.com/git-guide/index.ko.html\n- 한장으로 핵심 기능만: http://rogerdudler.github.com/git-guide/files/git_cheat_sheet.pdf\n\n\n## Commit\n\n커밋 합치기\n\n```\ngit rebase -i HEAD~4 // 최신 4개의 커밋을 하나로 합치기\n```\n\n커밋 메세지 수정\n\n```\n$ git commit --amend // 마지막 커밋메세지 수정(ref)\n```\n\n간단한 commit방법\n\n```\n$ git add {변경한 파일병}\n$ git commit -m “{변경 내용}\"\n```\n\n커밋 이력 확인\n\n```\n$ git log // 모든 커밋로그 확인\n$ git log -3 // 최근 3개 커밋로그 확인\n$ git log --pretty=oneline // 각 커밋을 한 줄로 표시\n$ git reflog // reset 혹은 rebase로 없어진 과거의 커밋 이력 확인\n```\n\n커밋 취소\n\n```\n$ git reset HEAD^ // 마지막 커밋 삭제\n$ git reset --hard HEAD // 마지막 커밋 상태로 되돌림\n$ git reset HEAD * // 스테이징을 언스테이징으로 변경, ref\n```\n\n\n## Branch\n\nmaster 브랜치를 특정 커밋으로 옮기기\n\n```\ngit checkout better_branch\ngit merge --strategy=ours master    # keep the content of this branch, but record a merge\ngit checkout master\ngit merge better_branch            # fast-forward master up to the merge\n```\n\n브랜치 목록\n\n```\n$ git branch // 로컬\n$ git branch -r // 리모트 \n$ git branch -a // 로컬, 리모트 포함된 모든 브랜치 보기\n```\n\n브랜치 생성\n\n```\ngit branch new master // master -\u003e new 브랜치 생성\ngit push origin new // new 브랜치를 리모트로 보내기\n```\n\n브랜치 삭제\n\n```\ngit branch -D {삭제할 브랜치 명} // local\ngit push origin :{the_remote_branch} // remote\n```\n\n빈 브랜치 생성\n\n```\n$ git checkout --orphan {새로운 브랜치 명}\n$ git commit -a // 커밋해야 새로운 브랜치 생성됨\n$ git checkout -b new-branch // 브랜치 생성과 동시에 체크아웃\n```\n\n리모트 브랜치 가져오기\n\n```\n$ git checkout -t origin/{가져올 브랜치명} // ref\n```\n\n브랜치 이름 변경\n\n```\n$ git branch -m {new name} // ref\n```\n\n\n## Tag\n\n\n태그 생성\n\n```\ngit tag -a {tag name} -m {tag message} {commit hash}\ngit tag {tag name} {tag name} -f -m \"{new message}\" // Edit tag message\n```\n\n태그 삭제\n\n```\ngit tag -d {tag name}\ngit push origin :tags/{tag name} // remote\n```\n\n태그 푸시\n\n```\ngit push origin --tags\ngit push origin {tag name}\ngit push --tags\n```\n\n\n## 기타 \n\n파일 삭제\n\n```\ngit rm --cached --ignore-unmatch [삭제할 파일명]\n```\n\n히스토리 삭제\n\n- 목적: 패스워드, 아이디 같은 비공개 정보가 담긴 파일을 실수로 올렸을 때 삭제하는 방법이다. (history에서도 해당 파일만 삭제)\n\n```\n$ git clone [url] # 소스 다운로드\n$ cd [foler_name] # 해당 폴더 이동\n$ git filter-branch --index-filter 'git rm --cached --ignore-unmatch [삭제할 파일명]' --prune-empty -- --all # 모든 히스토리에서 해당 파일 삭제\n$ git push origin master --force # 서버로 전송\n```\n\n히스토리에서 폴더 삭제:\n\n```\ngit filter-branch --tree-filter 'rm -rf vendor/gems' HEAD\n```\n\n리모트 주소 추가하여 로컬에 싱크하기\n\n```\n$ git remote add upstream {리모트 주소}\n$ git pull upstream {브랜치명}\n```\n\n최적화\n\n```\n$ git gc\n$ git gc --aggressive\n```\n\n## 서버 설정\n\n강제 푸시 설정\n\n```\ngit config receive.denynonfastforwards false\n```\n\n## Alias\n\n~/.gitconfig 파일을 설정하여 깃 명령어의 앨리어스를 지정할 수 있다.\n\n~/.gitconfig \u003e alias 부분:\n\n```\n\n[alias]\n  br = branch\n  co = checkout\n  rb = rebase\n  st = status\n  cm = commit\n  pl = pull\n  ps = push\n  lg = log --graph --abbrev-commit --decorate --format=format:'%C(cyan)%h%C(reset) - %C(green)(%ar)%C(reset)  %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(yellow)%d%C(reset)' --all\n  ad = add\n  tg = tag\n  df = diff \n```\n","funding_links":[],"categories":["Others"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjeonghwan-kim%2Fgit-usage","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjeonghwan-kim%2Fgit-usage","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjeonghwan-kim%2Fgit-usage/lists"}