Git & GitHub

hazel'sยท2022๋…„ 4์›” 6์ผ
0

git

๋ชฉ๋ก ๋ณด๊ธฐ
2/8

1

Git์ด๋ž€?

VCS - Version Control System (๋ฒ„์ „ ๊ด€๋ฆฌ ์‹œ์Šคํ…œ)

๐ŸŸฃ version์ด๋ž€?
ํ”„๋กœ์ ํŠธ๊ฐ€ ์ˆ˜์ •๋˜๋ฉด์„œ ์ถ•์ฒ™๋˜๋ฉด ๋ฒ„์ „์— ๋”ฐ๋ผ์„œ ๋ณด๊ณ ์„œ๋ฅผ ๋นจ๋ฆฌ ์ฐพ์„ ์ˆ˜ ์žˆ๋‹ค.

์˜ˆ>๋‚ ์งœ์™€ ์‹œ๊ฐ„์„ ์จ์„œ ๋งŒ๋“  ํŒŒ์ผ๋“ค vs ์ตœ์ข….txt ์ง„์งœ์ง„์งœ์ตœ์ข….txt

๐Ÿ“Œ ์ฝ”๋“œ ๋ฒ„์ „ ๊ด€๋ฆฌ๋ฅผ ํ•˜๋Š” ์ด์œ 
1. ์ˆ˜์ •ํ•  ๋•Œ ๋งˆ๋‹ค ํŒŒ์ผ์„ ์ƒˆ๋กœ ๋งŒ๋“ค๋ฉด ๊ด€๋ฆฌ๊ฐ€ ํž˜๋“ค๋‹ค.
2. ์–ธ์ œ๋“  ์ด์ „ ๋ฒ„์ „์˜ ์ฝ”๋“œ๋กœ ๋Œ์•„ ๊ฐˆ ์ˆ˜ ์žˆ๋‹ค.
3. ์ด๋ ฅ์„ ๋‚จ๊ธธ ์ˆ˜ ์žˆ๋‹ค.(๋‹ค๋ฅธ ์‚ฌ๋žŒ์˜ ์ฝ”๋“œ์— ๊ถ๊ธˆํ•œ ์ ์ด ์žˆ์œผ๋ฉด ๋ˆ„๊ฐ€ ์ž‘์—…ํ•œ์ง€ ํŒŒ์•… ํ•  ์ˆ˜ ์žˆ๋‹ค.=์ข€๋” ํšจ์œจ์ ์œผ๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.)
4. ์—ฌ๋Ÿฌ ๊ฐœ๋ฐœ์ž๋“ค์ด ํ˜‘์—…์œผ๋กœ ํ•˜๋‚˜์˜ ํ”„๋กœ์ ํŠธ๋ฅผ ์ง„ํ–‰ํ• ์ˆ˜ ์žˆ๋‹ค.
์˜ˆ> git, cvs, mercurial, susversion

GitHub์ด๋ž€?

์—ฌ๋Ÿฌ๊ฐœ์˜ branch์™€ ์ž‘์—…๋ฌผ๋“ค์ด ํ•˜๋‚˜๋กœ ๋ชจ์—ฌ์„œ ํ•˜๋‚˜์˜ ํ”„๋กœ์ ํŠธ๋กœ ๋งŒ๋“ค์ˆ˜ ์žˆ๋Š” ์‚ฌ์ดํŠธ.

  • Git์„ ์‚ฌ์šฉํ•œ ํ”„๋กœ์ ํŠธ๋“ค์˜ ์ €์žฅ์†Œ.
  • ๊ฐœ๋ฐœ์ž๋“ค์˜ Social Network.
    ์ด์Šˆ์— ๋Œ€ํ•ด์„œ ์„œ๋กœ ์˜๋…ผํ•  ์ˆ˜ ์žˆ๋‹ค.

Git์€ ํ”„๋กœ์ ํŠธ์˜ ๋ฒ„์ „๊ด€๋ฆฌ๋ฅผ ๋„์™€์ฃผ๋Š” ์‹œ์Šคํ…œ
GitHub์€ ๊นƒ์„ ์ด์šฉํ•ด ๋ฒ„์ „๊ด€๋ฆฌ๋ฅผ ํ•œ ํ”„๋กœ์ ํŠธ๋ฅผ ๊ด€๋ฆฌํ•ด์ฃผ๋Š” ํ˜ธ์ŠคํŒ… ์„œ๋น„์Šค

์‹ค์Šต

  1. git ์‹œ์ž‘ : git init
  2. git ์ƒํƒœ ํ™•์ธ : git status
    ์ง€๊ธˆ ๋‚ด๊ฐ€ ์ž‘์—…ํ•˜๊ณ  ์žˆ๋Š” ํŒŒ์ผ๋“ค์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.
  3. ํŒŒ์ผ ์ˆ˜์ • ์ด๋ ฅ ๊ธฐ๋ก ์ค€๋น„ : git add
    ์ž‘์—…ํ•œ ๋‚ด์šฉ์„ ์ €์žฅ : git add . =>ํ˜„์žฌ ํด๋”๋‚˜ ํ˜„์žฌ ๋””๋ ‰ํ† ๋ฆฌ ์ €์žฅ.
    ์˜ˆ>์žฅ๋ฐ”๊ตฌ๋‹ˆ
  4. ํŒŒ์ผ ์ˆ˜์ • ์ด๋ ฅ ๊ธฐ๋ก : git commit
  5. commit ์ด๋ ฅ ๋ณด๊ธฐ : git log
    git log์—์„œ ๋‚˜์˜ค๋ ค๋ฉด q๋ˆ„๋ฅด๋ฉด ๋œ๋‹ค.
    ์˜ˆ>์˜์ˆ˜์ฆ
    6.github ์ƒ์— ์˜ฌ๋ฆฌ๋ ค ํ• ๋•Œ : git push origin main

๐ŸŸฃ token

https (token) ์‚ฌ์šฉ์‹œ

echo "# git-practice" >> README.md
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/hyunny123/git-practice.git
git push -u origin main

์‹ค์Šต์„ ํ•˜๋ฉด์„œ git push origin master ์—์„œ ํ‚คํ† ํฐ์„ ๋„ฃ์œผ๋ผ๊ณ  ํ–ˆ์œผ๋‚˜ ๊ณ„์† ์˜ค๋ฅ˜๊ฐ€ ๋‚˜์„œ ์ทจ์†Œ ํ•˜๊ณ  git id๋ฅผ ๋„ฃ๊ณ  password์— keyrtoken์„ ์ž…๋ ฅํ•˜๋‹ˆ ํ™•์ธ๋จ.

git์— ๋งก๊ธฐ์ง€ ์•Š์„ ํŒŒ์ผํด๋”
.gitignore ๋งŒ๋“ค์–ด ๋ณด์•ˆ์ด ํ•„์š”ํ•œ ํŒŒ์ผ์„ ๊ทธ ์•ˆ์— ์ ์–ด์„œ ๋„ฃ๋Š”๋‹ค.
์˜ˆ) index-secret.html ํŒŒ์ผ๋ช…์„ ๊ทธ์•ˆ์— ์ ์–ด์„œ ๋„ฃ์œผ๋ฉด ๋œ๋‹ค.
์˜ˆ) *.yaml yaml๋กœ ๋œ ํŒŒ์ผ ๋ชจ๋‘
์˜ˆ) /folder/index.html

์šฐ์„  ํŒŒ์ผ์„ ๋ฐฑ์—…ํ•ด์„œ ์ €์žฅํ•ด๋‘๋Š”๊ฒƒ ์ค‘์š”!
๊ทธ๋ฆฌ๊ณ  ํŒŒ์ผ ์ €์žฅ์ด ์ค‘์š”!

git init
git add .
git commit์„ ํ•˜๊ฒŒ ๋˜๋ฉด 
i:์ž…๋ ฅ์‹œ์ž‘
esc:์ž…๋ ฅ์ข…๋ฃŒ
q:์ €์žฅ์—†์ด ์ข…๋ฃŒ
q!:์ €์žฅ์—†์ด ๊ฐ•์ œ์ข…๋ฃŒ
:wq: ์ €์žฅํ•˜๊ณ  ์ข…๋ฃŒ

i->first commit ->esc=>:wq ์ข…๋ฃŒ

git diff (๋ณ€๊ฒฝ์‚ฌํ•ญ์„ ๊ตฌ์ฒด์ ์œผ๋กœ)
j:์•„๋ž˜๋กœ ์Šคํฌ๋กค
k:์œ„๋กœ ์Šคํฌ๋กค
q:๋‹ซ๊ธฐ

์•ž์—์„œ๋Š” git commit์„ ํ•˜๊ณ  ๋ณต์žกํ•˜๊ฒŒ ํ–ˆ์ง€๋งŒ

git commit --m "first commit"

์ด๋ ‡๊ฒŒ ๊ฐ„๋‹จํ•˜๊ฒŒ ๋งŽ์ดํ•œ๋‹ค.

์ถ”๊ฐ€๋œ ํŒŒ์ผ์ด ์—†์„๋•Œ
add์™€ commit์„ ํ•œ๋ฒˆ์—

git commit -am "๋ฉ”์„ธ์ง€"

๐ŸŸฃ SHH

SHH keygen ์‚ฌ์šฉ์‹œ

echo "# ssh_test" >> README.md
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin git@github.com:hyunny123/ssh_test.git
git push -u origin main

ssh keygen ์„ค์น˜

ssh-keygen -t rsa

yesํ•˜๊ณ  ์•„์ด๋””์™€ ๋น„๋ฐ€๋ฒˆํ˜ธ ์„ค์ •
ssh ํด๋”๋กœ ๊ฐ€์„œ

cd ~/.ssh

keygen

cat id_rsa.pub

๊นƒํ—™์— setting -> SSH and GPG keys -> New SHH key -> terminal์—์„œ ํ‚ค๊ฐ’ ๋ณต์‚ฌํ•ด์„œ ๋ถ™์—ฌ๋„ฃ๊ธฐ

profile
์ข‹์•„ํ•˜๋Š” ๊ฒƒ์„ ํ•˜๋‚˜ํ•˜๋‚˜ ์ฑ„์›Œ๊ฐ€๋ฉด ํ–‰๋ณตํ•ด์งˆ๊บผ์•ผ

0๊ฐœ์˜ ๋Œ“๊ธ€