GIT icon indicating copy to clipboard operation
GIT copied to clipboard

๐Ÿ“š GIT ์‚ฌ์šฉ๋ฒ•์„ ๋ฐฐ์›Œ ๋ด…์‹œ๋‹ค ๐Ÿ”ฅ

๐Ÿš€GIT ์‚ฌ์šฉ๋ฒ•๐Ÿ›ฐ

Contents

  • GIT์„ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•œ ์ค€๋น„๐Ÿ’พ
    • git --version

  • GIT ์„ค์ •ํ•˜๊ธฐ๐Ÿ› 
    • git config --global user.name "์ด๋ฆ„"
    • git config --global user.email "์ด๋ฉ”์ผ"
    • git config --global --edit"
      • git config --global core.autocrlf input(Mac)
      • git config --global core.autocrlf true(Window)
      • git config --global core.editor "xed --wait"(Xcode)
      • git config --global core.editor "code --wait"(Visual Studio Code)

  • GIT ์ƒ์„ฑํ•˜๊ณ  ์‚ญ์ œํ•˜๊ธฐ๐Ÿ—‘
    • git init
    • rm -rf .git

  • Working Directory์—์„œ ํŒŒ์ผ Track ๋˜๋Š” Untrack ํ•˜๊ธฐ๐Ÿ‘€โœจ
    • git add ํŒŒ์ผ๋ช…
      • git add .
    • git rm --cached ํŒŒ์ผ๋ช…
    • echo ํŒŒ์ผ๋ช… > .gitignore
      • echo *.log > .gitignore
    • git status
      • git status -s

  • Staging Area์—์„œ Track๋œ ํŒŒ์ผ์˜ ๋ณ€๊ฒฝ์‚ฌํ•ญ ํ™•์ธํ•˜๊ธฐ๐Ÿ”
    • git diff
      • git diff --staged
    • git difftool
      • [diff] tool = vscode [difftool "vscode"] cmd = code --wait --diff $LOCAL $REMOTE

  • Commitํ•˜์—ฌ GIT์— ์ €์žฅํ•˜๊ณ , ๋ถˆ๋Ÿฌ์˜ค๊ธฐ๐Ÿ“ฅ๐Ÿ“ค
    • git commit -m "์ปค๋ฐ‹ ๋ฉ”์‹œ์ง€"
    • git log
      • git log --oneline --graph --all
    • git checkout ํ•ด์‹œ์ฝ”๋“œ

  • Alias๋ฅผ ์ด์šฉํ•˜์—ฌ ๋‚˜๋งŒ์˜ ๋‹จ์ถ• ๋ช…๋ น์–ด๋ฅผ ์‚ฌ์šฉํ•˜์žโœˆ
    • git config --global alias.๋ช…๋ น์–ด "๋‹จ์ถ•ํ•  ๋ช…๋ น์–ด"
    • git log --pretty=๋ช…๋ น์–ด

  • Log๋ฅผ ์ด์šฉํ•ด ํžˆ์Šคํ† ๋ฆฌ ์กฐํšŒํ•˜๊ธฐ(์‹ฌํ™”)๐Ÿ“‘
    • git log ๋ช…๋ น์–ด
      • git log -์ˆซ์ž
      • git log --before="๋‚ ์งœ"
      • git log --author="์ด๋ฆ„"
      • git log --grep="์ปค๋ฐ‹ ๋ฉ”์‹œ์ง€"
      • git log -S "ํŒŒ์ผ๋ช…"

  • [Control-Z] ๋˜๋Œ๋ฆฌ๊ธฐโ†ฉ
    • git commit --amend
    • git restore -- ํŒŒ์ผ๋ช…

  • Tag๋ฅผ ์ด์šฉํ•ด ๊ฐ„๋‹จํ•˜๊ฒŒ ๋ฒ„์ „ ํ‘œ์‹œํ•˜๊ธฐโœ’
    • git tag
      • git tag -l ํƒœ๊ทธ๋ช…
      • git tag -d ํƒœ๊ทธ๋ช…
    • git tag ํƒœ๊ทธ๋ช…
      • git tag ํƒœ๊ทธ๋ช… ํ•ด์‹œ์ฝ”๋“œ -a -m "ํƒœ๊ทธ ๋ฉ”์‹œ์ง€"
    • git show ํ•ด์‹œ์ฝ”๋“œ
      • git show head --name-only

  • Branch๋ฅผ ์ด์šฉํ•ด ๋…๋ฆฝ๋œ ๊ณต๊ฐ„์—์„œ ๋‚˜๋งŒ์˜ ์ž‘์—… ๊ณต๊ฐ„์„ ๋งŒ๋“ค์ž๐Ÿ—
    • git branch
      • git branch -v
      • git branch -all
      • git branch --merged
      • git branch --no-merged
    • git branch ๋ธŒ๋žœ์น˜๋ช…
      • git switch -C ๋ธŒ๋žœ์น˜๋ช…
    • git branch --move ๋ธŒ๋žœ์น˜๋ช… ๋ฐ”๊ฟ€๋ธŒ๋žœ์น˜๋ช…
    • git branch -d ๋ธŒ๋žœ์น˜๋ช…

  • Merge! ํ•˜๋‚˜์˜ Branch๋กœ ๋ณ‘ํ•ฉํ•˜๊ธฐ๐Ÿ”—
    • git merge ๋ธŒ๋žœ์น˜๋ช…
      • git merge --no-ff

  • Merge Conflict์™€ Merge Tool๐Ÿงท
    • git merge --abort
    • git merge --continue
    • git mergetool
      • [merge] tool = vscode [mergetool "vscode"] cmd = code --wait $MERGED

  • Rebase์™€ Cherry-Pick๐Ÿ’
    • git rebase ๋ธŒ๋žœ์น˜๋ช…
      • git rebase ๋ธŒ๋žœ์น˜๋ช… ๋ธŒ๋žœ์น˜๋ช…
      • git rebase --onto ๋ธŒ๋žœ์น˜๋ช… ๋ธŒ๋žœ์น˜๋ช… ๋ธŒ๋žœ์น˜๋ช…
      • git rebase --abort
      • git rebase --continue
    • git cherry-pick ํ•ด์‹œ์ฝ”๋“œ

  • GIT ๋„๊ตฌ - Stash, Cleanโ›
    • git stash push -m "์Šคํƒœ์‹œ ๋ฉ”์‹œ์ง€"
      • git stash
      • git stash -u
      • git stash --keep-index
    • git stash list
      • git stash show ์Šคํƒœ์‹œ
      • git stash show ์Šคํƒœ์‹œ --patch
    • git stach apply ์Šคํƒœ์‹œ
      • git stash pop ์Šคํƒœ์‹œ
    • git stash drop ์Šคํƒœ์‹œ
      • git stash clear
    • git stash branch ๋ธŒ๋žœ์น˜๋ช…
    • git clean
      • git clean -fd
      • git clean -x
      • git clean -d -n

  • Reset์œผ๋กœ ๋˜๋Œ์•„๊ฐ€๊ธฐโฎ
    • git reset
      • git reset --soft ํ•ด์‹œ์ฝ”๋“œ
      • git reset --hard ํ•ด์‹œ์ฝ”๋“œ
    • git restore --source=ํ•ด์‹œ์ฝ”๋“œ ํŒŒ์ผ๋ช…
    • git revert ํ•ด์‹œ์ฝ”๋“œ

  • GIT ๋„๊ตฌ - RefLog๐Ÿ“œ
    • git reflog
      • git reflog expire --expire=์‹œ๊ฐ„ --all
    • git show HEAD@{์ˆซ์ž}
    • git show ๋ธŒ๋žœ์น˜๋ช…@{์‹œ๊ฐ„}

  • Rebase -i ์˜ต์…˜์œผ๋กœ Commit ์ˆ˜์ •ํ•˜๊ธฐโœ‚
    • git rebase -i
      • git rebase --abort
      • git rebase --continue

  • GIT ๋„๊ตฌ - GIT์œผ๋กœ ๋ฒ„๊ทธ์ฐพ๊ธฐ(Blame, Bisect)๐Ÿ›
    • git blame ํŒŒ์ผ๋ช…
      • git blame -C -L ์ˆซ์ž,์ˆซ์ž ํŒŒ์ผ๋ช…
    • git bisect start
      • git bisect good
      • git bisect bad

  • GitHub - Remote ์ €์žฅ์†Œ ํ™œ์šฉํ•˜๊ธฐโ˜
    • git remote
      • git remote -v
      • git remote add origin ์ฃผ์†Œ
      • git remote remove ์ฃผ์†Œ
    • git clone ์ฃผ์†Œ
    • git push
    • git pull
    • git fetch

  • ์‹œ๋‚˜๋ฆฌ์˜ค - Pull request

  • Git๊ณผ Terminal ์ปค์Šคํ…€ ์„ธํŒ…โš™๏ธ
    • git config --global