๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐Ÿ‘จ‍๐Ÿš€ | OTHERS

[Git] Git ๋ช…๋ น์–ด ๋ชจ์Œ (for me)

by KASSID 2022. 1. 30.

๋ชฉ์ฐจ

    728x90

     ๋‚ด๊ฐ€ ์ฃผ๋กœ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ๋“ค 

    git add .

    - ๊นƒ์˜ ๊ด€๋ฆฌ ํ•˜์— ๋ชจ๋“  ํŒŒ์ผ์„ ๋‘๊ธฐ

     

    git status

    - ํ˜„์žฌ git์˜ ๊ด€๋ฆฌ ํ•˜์— ์žˆ๋Š” ํŒŒ์ผ๋“ค์˜ ์ƒํƒœ ๋ณด๊ธฐ

     

    git commit -m "์ปค๋ฐ‹๋ฉ”์‹œ์ง€"

    - ์ˆ˜์ • ์‚ฌํ•ญ ์ปค๋ฐ‹ํ•˜๊ธฐ

     

    git remote

    - ์ถ”๊ฐ€ํ•œ ์›๊ฒฉ ๋ ˆํŒŒ์ง€ํ† ๋ฆฌ ์ด๋ฆ„ ๋ฐ˜ํ™˜

     

    git branch

    - ๋กœ์ปฌ ๋ธŒ๋žœ์น˜ ๋ฐ˜ํ™˜

     

    git checkout (๋ธŒ๋žœ์น˜๋ช…)

    - ํ•ด๋‹น ๋ธŒ๋žœ์น˜๋กœ ๋„˜์–ด๊ฐ€๊ธฐ

     

    git push (์›๊ฒฉ๋ช…) (๋ธŒ๋žœ์น˜๋ช…)

    - ๋ธŒ๋žœ์น˜๋ฅผ ์›๊ฒฉ์— ์˜ฌ๋ฆฌ๊ธฐ --> ๊นƒํ—ˆ๋ธŒ ์ƒˆ๋กœ๊ณ ์นจ ํ›„ ๋ธŒ๋žœ์น˜ ํด๋ฆญ --> ์ถ”๊ฐ€๋จ

     

    git pull (์›๊ฒฉ๋ช…) (๋ธŒ๋žœ์น˜๋ช…)

    - ๊นƒํ—ˆ๋ธŒ์—์„œ ๋‹ค์šด๋ฐ›์•„์•ผ ํ•  ๊ฒƒ ๋กœ์ปฌ๋กœ ๋‹ค์šด๋ฐ›๊ธฐ

     


     ๊ทธ ์™ธ ๋ช…๋ น์–ด๋“ค! (๊ณ„์† ์ถ”๊ฐ€ ์ค‘) 

    git remote add "์›๊ฒฉ๋ช…" "๊นƒํ—ˆ๋ธŒ ์ฃผ์†Œ"

    - ํ˜„์žฌ github ๋ ˆํŒŒ์ง€ํ† ๋ฆฌ๋ฅผ ์ง€์ •ํ•œ ์ด๋ฆ„์˜ ์›๊ฒฉ ์ €์žฅ์†Œ๋กœ ์„ค์ •ํ•˜๊ฒ ๋‹ค.

     

    git log

    - ํ”„๋กœ์ ํŠธ ๋‚ด์—ญ ํ™•์ธ

     

    git fetch

    - github์—์„œ์˜ ์†Œ์‹ ์•Œ์•„๋ณด๊ธฐ

     

    git fetch --> git status

    - ๊นƒํ—ˆ๋ธŒ์—์„œ ๋‹ค์šด๋ฐ›์•„์•ผ ํ•  ์‚ฌํ•ญ์ด ์žˆ๋Š”์ง€ ํ™•์ธ
    Ex. "Your branch is behind 'origin/master' by 1 commit, and can be fast-forwarded" (์›๊ฒฉ๋ช… origin/์›๊ฒฉ๋ธŒ๋žœ์น˜ master)

    = ์ด ๋กœ์ปฌ branch๊ฐ€ origin์ด๋ผ๋Š” ์ฃผ์†Œ์˜ master branch๋ณด๋‹ค 1์ปค๋ฐ‹์ด ๋’ค์ณ์ ธ์žˆ๋‹ค.


    git checkout (๋ธŒ๋žœ์น˜๋ช…)

    - ์‚ฌ์šฉํ•  ๋กœ์ปฌ ๋ธŒ๋žœ์น˜๋กœ ๋„˜์–ด๊ฐ€๊ธฐ

     

    git checkout -b (๋ธŒ๋žœ์น˜๋ช…)

    - ๋ธŒ๋žœ์น˜ ๋งŒ๋“  ๋‹ค์Œ ๋„˜์–ด๊ฐ€๊ธฐ๋ฅผ ํ•œ๋ฒˆ์—!

     

    git checkout -b (๋กœ์ปฌ ๋ธŒ๋žœ์น˜๋ช…) (์›๊ฒฉ๋ช…)/(๋ธŒ๋žœ์น˜๋ช…)

    - ๋กœ์ปฌ์— (๋ธŒ๋žœ์น˜๋ช…) ์œผ๋กœ ๋ธŒ๋žœ์น˜๋ฅผ ๋งŒ๋“ค์–ด์„œ origin ์ด๋ผ๋Š” ์›๊ฒฉ์˜ (๋ธŒ๋žœ์น˜๋ช…)์˜ ๋‚ด์šฉ์„ ๋ฐ›์•„์˜ค๊ณ  ๊ทธ ํ‰ํ–‰์šฐ์ฃผ๋กœ ์ฒดํฌ์•„์›ƒ ํ•œ๋‹ค.
    - ํŒŒ์ผ ์ƒํƒœ๊ฐ€ ๋กœ์ปฌ์—๋„ ๋ฐ˜์˜๋จ--> git branch๋กœ ๋กœ์ปฌ์—์„œ ๋ธŒ๋žœ์น˜ ๋ชฉ๋ก ํ™•์ธ์œผ๋กœ๋„ ์•Œ ์ˆ˜ ์žˆ์Œ

     

    ์„œ๋กœ ๋‹ค๋ฅธ ์‚ฌ์šฉ์ž๊ฐ€ ๊ฐ™์€ ํŒŒ์ผ์„ ์ˆ˜์ •ํ•˜๊ณ  git push๋ฅผ ํ•˜๋ ค๊ณ  ํ•˜๋ฉด ์—๋Ÿฌ ๋ฉ”์‹œ์ง€ --> ์ผ๋‹จ pull ์„ ํ•ด์„œ ํ˜„ ์ƒํƒœ๋ฅผ ์—…๋ฐ์ดํŠธ ์‹œํ‚จ ํ›„ ์ถฉ๋Œ์„ ํ•ด๊ฒฐํ•˜๊ณ  push ํ•ด์•ผ ํ•จ


    git branch (๋ธŒ๋žœ์น˜๋ช…)

    - ๋กœ์ปฌ ๋ธŒ๋žœ์น˜ ๋งŒ๋“ค๊ธฐ

     

    git branch -a

    - ๋กœ์ปฌ๊ณผ ์›๊ฒฉ ๋ชจ๋‘์˜ ๋ธŒ๋žœ์น˜ ๋ณด๊ธฐ

     

    git branch -r

    - ์›๊ฒฉ ๋ธŒ๋žœ์น˜ ๋ณด๊ธฐ

     

    git branch -d (๋ธŒ๋žœ์น˜๋ช…)

    - ๋กœ์ปฌ ๋ธŒ๋žœ์น˜ ์‚ญ์ œ, ์ œ๊ฑฐํ•˜๊ธฐ

     

    git branch --set-upstream-to (์›๊ฒฉ๋ช…)/(๋ธŒ๋žœ์น˜ ๋ช…)

    - ๋กœ์ปฌ ๋ธŒ๋žœ์น˜์™€ ์›๊ฒฉ ๋ธŒ๋žœ์น˜๋ฅผ ์—ฐ๋™์‹œํ‚จ๋‹ค. (๋กœ์ปฌ ๋ธŒ๋žœ์น˜๋ฅผ ๋ณ€๊ฒฝํ•˜๋ฉด ์ž๋™์œผ๋กœ ๋ฐ˜์˜์ด ๋จ)


    git push origin (๋ธŒ๋žœ์น˜๋ช…)

    - ๋กœ์ปฌ๋ธŒ๋žœ์น˜๋ฅผ ์›๊ฒฉ ๋ธŒ๋žœ์น˜์— ์˜ฌ๋ฆฌ๊ธฐ --> git branch -r ๋กœ ํ™•์ธ!

    (or ๊นƒํ—ˆ๋ธŒ ์ƒˆ๋กœ๊ณ ์นจ ํ›„ ๋ธŒ๋žœ์น˜ ํด๋ฆญ --> ์ถ”๊ฐ€๋จ)

    - pushํ•  ๋•Œ๋„ ์‚ฌ์šฉํ•จ

     

    git push -d (์›๊ฒฉ๋ช… origin) (๋ธŒ๋žœ์น˜๋ช…)

    - ์›๊ฒฉ์˜ ๋ธŒ๋žœ์น˜ ์‚ญ์ œ, ์ œ๊ฑฐํ•˜๊ธฐ


     ๋‚˜๋ฅผ ์œ„ํ•œ github ์ •๋ฆฌ 

     

    - github์— push ํ•˜๊ธฐ ์ „์— branch๋ฅผ ํ™•์ธํ•˜์ž! (master, DESK ๋“ฑ)

    - pull์„ ํ†ตํ•ด ๋กœ์ปฌ๋กœ ๊ฐ€์ ธ์˜ฌ ๋•Œ branch๋ณ€๊ฒฝ ํ™•์ธํ•˜๊ณ  ํ•˜๊ธฐ

     

    - ๋งŒ์•ฝ ์•„๋ž˜์˜ ์˜ค๋ฅ˜์— ๋Œ€ํ•ด์„œ.

    ์ด error๋Š” root๊ฐ€ ๋‹ฌ๋ผ์„œ ๋ฐœ์ƒํ•œ๋‹ค.

    (๋‚˜์˜ ๊ฒฝ์šฐ์—๋Š” remote๋œ ์ฃผ์†Œ๊ฐ€ ์ž˜๋ชป๋˜์–ด์„œ ๋ฐœ์ƒํ•จ! .git ์ด์Šˆ..)

     

    - ๋กœ์ปฌ branch vs ์›๊ฒฉ branch

    ์„œ๋กœ ๋‹ค๋ฅด๋‹ค.. ๊ทธ๋Ÿฌ๋ฏ€๋กœ ์—ฐ๋™์„ ํ•ด์ฃผ๋Š” ๊ฒƒ์ด ์ข‹์€ ๋“ฏ!

     

     

     

     

    ๋Œ“๊ธ€