2 ๋ถ„ ์†Œ์š”



push & pull & clone

push

  • ๋กœ์ปฌ ์ €์žฅ์†Œ์—์„œ ๊ด€๋ฆฌํ•œ ๋ฒ„์ „ ์ด๋ ฅ์„ ์›๊ฒฉ ์ €์žฅ์†Œ(github)์œผ๋กœ ์—…๋กœ๋“œ ํ•˜๋Š” ๋ช…๋ น์–ด

      $ git push origin master
    
  • ์ฐธ๊ณ 

    $ git push -u origin master # ์—ฌ๊ธฐ์„œ -u๋Š” ์ตœ์ดˆ 1ํšŒ๋งŒ ๋ถ™์ด๋ฉด ๋ฉ๋‹ˆ๋‹ค. (์ตœ์†Œ 1ํšŒ push ํ•  ๋•Œ๋งŒ ๋ถ™์ด์ž!)
    



pull

  • ์›๊ฒฉ ์ €์žฅ์†Œ์˜ ๋ณ€๊ฒฝ ์‚ฌํ•ญ์„ ๋ฐ›์•„์˜ด(์—…๋ฐ์ดํŠธ)
  • commit ๋‚ด์—ญ์„ ๊ธฐ๋ฐ˜์œผ๋กœ ๋ณ€๊ฒฝ ์‚ฌํ•ญ์„ ์ƒˆ๋กœ ๊ฐฑ์‹ ํ•˜๋Š” ํ–‰์œ„
$ git pull origin master # git์•„ pull(์—…๋ฐ์ดํŠธ ํ•ด์ค˜) origin ์ด๋ผ๋Š” ์›๊ฒฉ ์ €์žฅ์†Œ๋กœ๋ถ€ํ„ฐ master ๋ธŒ๋žœ์น˜๋ฅผ!
$ git pull origin master
remote: Enumerating objects: 4, done.
remote: Counting objects: 100% (4/4), done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), 739 bytes | 67.00 KiB/s, done.
From https://github.com/IT3AI1/TIL
 * branch            master     -> FETCH_HEAD
   d2c6be1..29e2c44  master     -> origin/master
Updating d2c6be1..29e2c44
Fast-forward
 README.md | 2 ++
 1 file changed, 2 insertions(+)
 create mode 100644 README.md

  • ์›๊ฒฉ์ €์žฅ์†Œ์— read.me๋ฅผ ์ถ”๊ฐ€ํ•œ ํ›„ pull์„ ํ•œ ๊ฒฐ๊ณผ์ด๋‹ค.



clone

  • ์›๊ฒฉ ์ €์žฅ์†Œ ์ „์ฒด๋ฅผ ๋ณต์ œ
  • ์ตœ์ดˆ 1ํšŒ๋งŒ ์ˆ˜ํ–‰

  • ํด๋ก  ๋ฐ›์€ ํ”„๋กœ์ ํŠธ๋Š” ์ž๋™์œผ๋กœ .git์ด ์„ค์ •๋˜์–ด ์žˆ์Œ (+ remote๋„ ๋“ฑ๋ก๋˜์–ด ์žˆ์Œ)
    • ๋ณต์ œํ•œ๊ฑฐ๋‹ˆ๊นŒ!
$ git clone ๋ณต์ œํ• ์ €์žฅ์†ŒURL

image

๋งŒ์•ฝ ์›๊ฒฉ ์ €์žฅ์†Œ์˜ ์ด๋ฆ„์ด ์•„๋‹Œ ๋‹ค๋ฅธ ์ด๋ฆ„์œผ๋กœ ํด๋”๋ฅผ clone ๋ฐ›๊ณ  ์‹ถ๋‹ค๋ฉด?

$ git clone ์›๊ฒฉ์ €์žฅ์†ŒURL clone๋ฐ›์„ํด๋”์ด๋ฆ„

# ์˜ˆ์‹œ
$ git remote add origin https://github.com/IT3AI1/TIL.git TIL-test



push & pull(+clone) ์‹œ๋‚˜๋ฆฌ์˜ค

์ตœ์ดˆ 1ํšŒ clone ์ดํ›„ add, commit, push & pull, add, commit, push

image-20210705173745218



gitignore

git์ด ์–ด๋– ํ•œ ํด๋” / ํŒŒ์ผ์˜ ๋ฒ„์ „ ๊ด€๋ฆฌ๋ฅผ ๋ฌด์‹œํ•  ์ˆ˜ ์žˆ๋„๋ก ์ ์–ด๋‘๋Š” ๋ฌธ์„œ -> ์—ฌ๊ธฐ์— ์ ํžŒ ๋‚ด์šฉ์€ git์ด ๋ฒ„์ „ ๊ด€๋ฆฌ๋ฅผ ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

  • ์ผ๋ฐ˜์ ์œผ๋กœ ๊ฐœ์ธ์ •๋ณด ๋ฐ ํŠน์ • ์‚ฌ๋žŒ์—๊ฒŒ๋งŒ ์ ์šฉ๋˜๋Š” ๊ฐœ๋ฐœ ํ™˜๊ฒฝ๊ณผ ๊ฐ™์€ ์„ค์ •์ด ํฌํ•จ๋จ
    • ๊ฐœ๋ฐœํ•  ๋•Œ ์‚ฌ์šฉํ•˜๋Š” secret key, (๋ณด์•ˆ์ƒ์˜ ์ด์œ ๋กœ) github๊ณผ ๊ฐ™์€ ์›๊ฒฉ์ €์žฅ์†Œ์— ์—…๋กœ๋“œ๋˜๋ฉด ์•ˆ๋˜๋Š” ์ •๋ณด ๋“ฑ์€ git์ด ๋ฒ„์ „ ๊ด€๋ฆฌ๋ฅผ ํ•˜๋ฉด ์•ˆ๋จ
  • ๊ทธ๋ฆฌ๊ณ  ๋ฒ„์ „ ๊ด€๋ฆฌ๊ฐ€ ํ•„์š”์—†๋‹ค๊ณ  ์ƒ๊ฐ๋˜๋Š” ํด๋” ํ˜น์€ ํŒŒ์ผ๋„ ํฌํ•จ ์‹œํ‚ฌ ์ˆ˜ ์žˆ์Œ
  • .gitignore ํŒŒ์ผ์„ ๋งŒ๋“ค์–ด์„œ ๊ด€๋ฆฌํ•œ๋‹ค.
  • ์ผ๋ฐ˜์ ์œผ๋กœ git init ์„ ์ง„ํ–‰ํ•˜๊ธฐ ์ „์— ๋งŒ๋“ ๋‹ค.
practice # ํŠน์ •ํ•œ ํด๋”๋ฅผ git์ด ๊ด€๋ฆฌํ•˜์ง€ ์•Š๊ฒŒํ•จ
a.txt # ํŠน์ •ํ•œ ํŒŒ์ผ์„ git์ด ๊ด€๋ฆฌํ•˜์ง€ ์•Š๊ฒŒํ•จ
*.txt # ํŠน์ •ํ•œ ํ™•์žฅ์ž๋ฅผ ๊ฐ€์ง„ ํŒŒ์ผ์„ git์ด ๊ด€๋ฆฌํ•˜์ง€ ์•Š๊ฒŒํ•จ

image



gitignore.io

https://gitignore.io/

  • .vscode / .DS_Store -> ๋ณด์•ˆ์ƒ์˜ ์ด์œ ๊ฐ€ ์•„๋‹ˆ๋”๋ผ๋„ ๋ฒ„์ „ ๊ด€๋ฆฌ์˜ ํ•„์š”์„ฑ์ด ์—†๋Š” ์นœ๊ตฌ๋“ค์ด ์กด์žฌ..!

  • ๋ฏธ๋ฆฌ ํŠน์ •ํ•œ ์–ธ์–ด, ํ”„๋ ˆ์ž„์›Œํฌ, ์šด์˜ ์ฒด์ œ ๋“ฑ์—์„œ git์œผ๋กœ ๋ฒ„์ „ ๊ด€๋ฆฌ๋ฅผ ํ•  ํ•„์š”๊ฐ€ ์—†๋Š” ์š”์†Œ๋ฅผ ๋ˆ„๊ตฐ๊ฐ€! ๋ฏธ๋ฆฌ ๋งŒ๋“ค์–ด ๋†“์•˜์Œ
  • ์–ธ์–ด, ํ”„๋ ˆ์ž„์›Œํฌ, ์šด์˜์ฒด์ œ ๋“ฑ์„ ๊ฒ€์ƒ‰ํ•˜๊ณ  โ€˜์ƒ์„ฑโ€™ ๋ฒ„ํŠผ์„ ๋ˆ„๋ฅด๋ฉด ์ž๋™์œผ๋กœ ํ•„์š”ํ•œ ๋‚ด์šฉ์„ ๋งŒ๋“ค์–ด ์ค€๋‹ค.



๋‹ค์‹œ ์ •๋ฆฌ!

  • gitignore๋Š” ์–ด๋Š ์‹œ์ ์— ๋งŒ๋“œ๋Š” ๊ฒƒ์ด ์ข‹์„๊นŒ์š”?
    • git init ์ „/ํ›„
  • gitignore ํŒŒ์ผ์ด ์œ„์น˜ํ•˜๋Š” ๊ณณ์€ ์–ด๋””์ผ๊นŒ์š”?
    • ์ผ๋ฐ˜์ ์œผ๋กœ .git ํด๋”๊ฐ€ ์กด์žฌํ•˜๋Š” ๊ณณ์— ์ƒ์„ฑ



push error

$ git push origin main
To https://github.com/IT3AI1/practice.git
 ! [rejected]        main -> main (non-fast-forward)
error: failed to push some refs to 'https://github.com/IT3AI1/practice.git'   # ๊ฑฐ์ ˆ๋จ...
hint: Updates were rejected because the tip of your current branch is behind  
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.     



ํ•ด์„

# ์›๊ฒฉ ์ €์žฅ์†Œ๋กœ pushํ•˜๋Š” ๊ฒƒ์„ ์‹คํŒจํ–ˆ์Œ..
error: failed to push some refs to 'https://github.com/IT3AI1/practice.git' 

# update๊ฐ€ reject๋˜์—ˆ๋Š”๋ฐ ์™œ๋ƒ๋ฉด... remote์— local ์—†๋Š” ์–ด๋–ค ๋ณ€๊ฒฝ ์‚ฌํ•ญ์ด ์žˆ์Œ...
hint: Updates were rejected because the remote contains work that you do

# ์ด๋Ÿฌํ•œ ์ƒํ™ฉ์€ ์ปค๋ฐ‹์ด ๋‹ค๋ฅธ ๊ฒฝ์šฐ์— ๋ฐœ์ƒํ•˜๋Š”๋ฐ.. remote ์ €์žฅ์†Œ์™€ local ์ €์žฅ์†Œ๋ฅผ ์ผ์น˜ ์‹œ์ผœ์•ผ ํ•  ๊ฒƒ ๊ฐ™์Œ...
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes

# ์–ด.. git pull ํ•œ๋ฒˆ ํ•ด๋ณผ๋ž˜?? ์–ธ์ œ?? ๋‹ค์‹œ push ํ•˜๊ธฐ ์ „์—...
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
  1. ๋กœ์ปฌ ์ €์žฅ์†Œ(๋‚ด ์ปดํ“จํ„ฐ)์™€ ์›๊ฒฉ ์ €์žฅ์†Œ(github)์˜ commit ์ด๋ ฅ์„ ๋น„๊ตํ•ด๋ณธ๋‹ค!
    • ์ด ๋ฌธ์ œ๋Š” ๋กœ์ปฌ ์ €์žฅ์†Œ์™€ ์›๊ฒฉ ์ €์žฅ์†Œ์˜ commit ์ด๋ ฅ์ด ๋‹ค๋ฅด๊ธฐ ๋•Œ๋ฌธ์— ๋ฐœ์ƒํ•˜๋Š” ๋ฌธ์ œ
    • ์ฃผ๋กœ ์ง‘์—์„œ push๋ฅผ ํ•˜๊ณ  ๊ฐ•์˜์žฅ์— ๊ฐ€์„œ pullํ•˜์ง€ ์•Š์€ ์ฑ„๋กœ ์ž‘์—…ํ•˜๊ณ  add, commit ์ดํ›„์— push๋ฅผ ํ•˜๋ฉด ๋ณด๊ฒŒ ๋˜๋Š” ๋ฉ”์‹œ์ง€
  2. ๋กœ์ปฌ ์ €์žฅ์†Œ์—์„œ $ git pull origin master๋ฅผ ์ง„ํ–‰ํ•œ๋‹ค.
  3. vs code ์ฐฝ์ด ๋‚˜์˜ค๋ฉด text ํŒŒ์ผ์„ x ๋ฒ„ํŠผ์„ ๋ˆŒ๋Ÿฌ์„œ ์ข…๋ฃŒ ํ•œ๋‹ค.
    • ์ด๋•Œ vs code ์ฐฝ์ด ์—ด๋ฆฌ์ง€ ์•Š๋Š” ๊ฒฝ์šฐ๋„ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ๋‹นํ™ฉํ•˜์ง€ ๋ง ๊ฒƒ!



References

ํƒœ๊ทธ:

์นดํ…Œ๊ณ ๋ฆฌ:

์—…๋ฐ์ดํŠธ:

๋Œ“๊ธ€๋‚จ๊ธฐ๊ธฐ