hhnn_soph
[Git] GitHub Repository ์์ฑ ๋ฐ git pull/git pushํ๊ธฐ ๋ณธ๋ฌธ
๐ GitHub์ด๋?
Git์ ๋ค์ด๋ดค๋ค๋ฉด GitHub๋ ์์์ผ ํ๋ค! ๋์ ์์ฐํ ๋ค๋ฅธ ๊ฒ!
Git | GitHub |
์ฝ๋ ๋ฒ์ ๊ด๋ฆฌ ํ๋ก๊ทธ๋จ | Git์ผ๋ก ๊ด๋ฆฌํ๋ ํ๋ก์ ํธ๋ฅผ ์ฌ๋ ค๋ ์ ์๋ ์ฌ์ดํธ |
Local Repository (๋ด ์ปดํจํฐ์ .git ๋ ํ์งํ ๋ฆฌ) |
Remote Repository (์๊ฒฉ ์ ์ฅ์, Local Repository์ ๋ณต์ ๋ณธ) |
GitHub์ ํตํด ๋ด ์ปดํจํฐ์ ์์ ๋ฌผ์ ์ธ๋ถ ์ปดํจํฐ์ ๋ฐฑ์ ๋ณธ์ ๋ง๋ค์ด ๋์ ์ ์๋ค. ๋ฐ๋ผ์ ๋ค๋ฅธ ์ฌ๋์ด ์ฌ๋ ค๋ ๊ฒ์ ๋ค์ด๋ฐ์์ ์์ ํ๊ณ ์ฌ๋ ค๋ ์ ์๊ธฐ ๋๋ฌธ์ ํ์ ์ด ๊ฐ๋ฅํ๋ค.
๐ GitHub์์ ๋ ํฌ์งํ ๋ฆฌ ์์ฑํ๊ธฐ
1. GitHub ๊ฐ์ ํ ์๋ ๊ฒฝ๋ก๋ก ๋ ํฌ์งํ ๋ฆฌ๋ฅผ ์์ฑํ์.
2. ์์ New๋ฅผ ํด๋ฆญํ๋ฉด ๋ค์๊ณผ ๊ฐ์ด Create a new repository ํ์ด์ง๊ฐ ๋์จ๋ค.
- Repository name : ๋ก์ปฌ ๋ ํฌ์งํ ๋ฆฌ ์ด๋ฆ๊ณผ ๊ฐ์ด ์์ฑํด๋ ๋๊ณ , ์ํ๋ ๋ฐ๋ก ์์ฑํ๋ฉด ๋๋ค.
- Description : ๋ ํฌ์งํ ๋ฆฌ์ ๋ํ ์ค๋ช ์ ์ ์ผ๋ฉด ๋๋๋ฐ, ๋ ๊ฐ์ ๊ฒฝ์ฐ๋ ํ๋ก์ ํธ ํน์ฑ์ ๊ฐ๋จํ ์๋ค.
- ๊ทธ ์๋ ๋ถ๋ถ์ ์์ ์ด ์ํ๋ ์ต์ ์ ์ ํํด ์ค ํ Create repository๋ฅผ ํด๋ฆญํ๋ฉด ์์ฑ๋๋ค!
๐ ๋ก์ปฌ ๋ ํฌ์งํ ๋ฆฌ๋ฅผ GitHub์ ์ ๋ก๋ํ๊ธฐ
Create repository๋ฅผ ํด๋ฆญํ๋ฉด ์๋์ ๊ฐ์ ํ๋ฉด์ด ๋์จ๋ค.
์ด๋ฏธ ๋ก์ปฌ ๋ ํฌ์งํ ๋ฆฌ๊ฐ ์๋ ๊ฒฝ์ฐ์ 1๋ฒ์งธ๋ฅผ, ์๋ ๊ฒฝ์ฐ์ 2๋ฒ์งธ๋ฅผ ์คํํ๋ฉด ๋๋ค!
๋.. ๋ด ํ๋ก์ ํธ ํด๋๋ฅผ ๋ก์ปฌ ๋ ํฌ์งํ ๋ฆฌ๋ก ๋ง๋ค์ง ์์๊ธฐ ๋๋ฌธ์ 1๋ฒ์งธ ๋ช ๋ น๋ฌธ๋ค์ ์คํํ์๋ค.
(๋จ, READEME.md๋ฅผ ์์ฑํ์ง ์์ ๊ฒ์ด๊ธฐ์ echo ~, git add README.md ๋ช ๋ น์ด๋ ์คํํ์ง ์์๋ค.)
โญ ์ฌ๊ธฐ์ ๋์ฌ๊ฒจ๋ณผ ๊ฒ์ด ์๋๋ฐ.. ๋ฐ๋ก main์ด๋ค. git push -u origin master๊ฐ ์๋๋ผ origin main์ด๋ผ๋.
๋ณ๊ฒฝ๋ main์ด๋ ๋ธ๋ ์น๋ช ๊ณผ ์ถ๊ฐ๋ 'git branch -M main' ๋ช ๋ น์ด๊ฐ ์ด์ํด์ ์ฐพ์๋ณด์๋ค.
ํ์ธํด๋ณด๋, 'Black Lives Matter' ์ด๋์ ๋ฐ๋ง์ถฐ ๋ ธ์์ ๋ฅผ ์ฐ์์ํค๋ master๋ ๋ํดํธ ๋ธ๋ ์น๋ช ์ main์ผ๋ก ๋ฐ๊พผ ๊ฒ์ด์๋ค! master๋ก push ํ๋ฉด ์ปค๋ฐ์ด ์ ๋๋ก ๋์ง ์์ ์ ์์ผ๋ ์ ์ํ์!
๐ Git Push & Git Pull ํ๊ธฐ
์์ฒ๋ผ ๋ก์ปฌ ๋ ํฌ์งํ ๋ฆฌ๋ฅผ ๊นํ๋ธ์ ์ ๋ก๋ํ๋ค๋ฉด push์ pull์ ์ฌ์ฉํ ์ ์๋ค.
Push์ Pull๋ ๋ก์ปฌ ํน์ ๋ฆฌ๋ชจํธ ๋ ํฌ์งํ ๋ฆฌ์ ๋ณ๊ฒฝ์ฌํญ์ด ์๊ธฐ๋ฉด ๊ทธ ๋ด์ฉ์ ์๋ก์๊ฒ ๋ณด๋ด์ค ๋ ์ฌ์ฉํ๋ ๋ช ๋ น์ด์ด๋ค.
No. | ์๋ก์ด ์ปค๋ฐ ๋ณด๋ด๊ธฐ | ๋ช ๋ น์ด | ||
1 | Local Repository | > | Remote Repository | git push |
2 | Remote Repository | > | Local Repository | git pull |
1. Git Push
Local Repository์์ ๋ฐ๋ ๋ด์ฉ์ Remote Repository์๋ ๋ฐ์ํ๊ธฐ ์ํด ์ฐ๋ ๋ช ๋ น์ด์ด๋ค.
$ git add .
$ git commit -m "write a commit message"
$ git push
Push ์ ์๋ ๋ฐ๋์ git add . & git commit -m "write a commit message" 2๊ฐ์ง๋ฅผ ์ํํด์ผ ํ๋ค.
๊ทธ๋ฆฌ๊ณ ์ฌ๊ธฐ์ ์ค์ํ ๊ฒ์ด ์๋ค!
$ git push [์ ์ฅ์๋ช
] [๋ธ๋์น๋ช
]
git push ๋ช ๋ น์ด๋ ์๋ ์์ ๊ฐ์ด ์๊ฒฉ ์ ์ฅ์๋ช ๊ณผ ๋ธ๋์น๋ช ์ ์ธ์๋ก ๋ฐ๋๋ค.
๊ทธ๋ฌ๋ ์ด๋ฏธ GitHub ์ฐ๋ ์ -u ์ต์ ์ ์ฌ์ฉํด push ํ๊ธฐ ๋๋ฌธ์ ์ปค๋ฐ ํ "git push" ๋ช ๋ น์ด๋ง ์ฌ์ฉํ ์ ์๋ ๊ฒ์ด๋ค.
$ git push -u origin main
# -u ์ต์
: ํด๋น ์ต์
์ ์ฌ์ฉํด ์ต์ด ํ๋ฒ๋ง ์ ์ฅ์๋ช
๊ณผ ๋ธ๋์น๋ช
์ ์
๋ ฅํ๋ฉด ๊ทธ ์ดํ๋ ์๋ตํ ์ ์๋ค.
# remote ์ ์ฅ์๋ช
์์๋ด๊ธฐ
$ git remote
origin
$ git push -u origin main
Username for 'https://github.com': (์ฌ์ฉ์์ด๋ฆ)
Password for 'https://(์ฌ์ฉ์์ด๋ฆ)@githum.com': (๋น๋ฐ๋ฒํธ)
โญ ํด๋น ๋ฆฌ๋ชจํธ ๋ ํฌ์งํ ๋ฆฌ์ ๋ช ๋ฒ ์ปค๋ฐํ๋์ง ๋ณด๊ณ ์ถ๋ค๋ฉด ์๋์ ๊ฐ์ ๊ฒฝ๋ก๋ก ํ์ธํ ์ ์๋ค.
2. Git Pull
Remote Repository์์ ๋ฐ๋ ๋ด์ฉ์ Local Repository์๋ ๋ฐ์ํ๊ธฐ ์ํด ์ฐ๋ ๋ช ๋ น์ด์ด๋ค.
ํ๋ก Git์ ์ฐ์ตํ๋ ์ค Pull์ ์ธ์ ์ฐ๋์ง ์ ํ ๊ฐ์ด ์ค์ง ์์๋๋ฐ.. ์๋์ ๊ฐ์ ์ํฉ์์ ๋ง์ด ์ฐ์ธ๋ค๊ณ ํ๋ค!
(์ญ์ GitHub์ ํ์ ์ ๋ฅํตํ๋ค..)
- GitHub ํ์ด์ง์์ ์ง์ ๋ด์ฉ์ ์์ ํ ๊ฒฝ์ฐ (ex. README.md ํ์ผ ์์ )
- ๋ค๋ฅธ ์ฌ๋์ด ๊ทธ ๋ฆฌ๋ชจํธ ๋ ํฌ์งํ ๋ฆฌ๋ฅผ ์์ ์ ์ปดํจํฐ๋ก ๊ฐ์ ธ๊ฐ์ ์์ ํ ๋ค์ ๋ค์ ๋ฆฌ๋ชจํธ ๋ ํฌ์งํ ๋ฆฌ์ git push ํ ๊ฒฝ์ฐ
์ฆ, ํ์ ํ๋ ๊ฒฝ์ฐ push-pull์ ํตํด ์๋ก์ ์ฝ๋๋ฅผ ๋ฐ์๋ณด๊ธฐ ์ํด ์ฌ์ฉ
$ git pull
$ cat README.md
# cat [ํ์ผ๋ช
.ํ์ฅ์] ๋ช
๋ น์ด: ํด๋น ํ์ผ์ ๋ด์ฉ์ ๋ชจ๋ ์ถ๋ ฅํ๋ค.
pull์ ๋ฐ์ ํ cat ๋ช ๋ น์ด๋ฅผ ํตํด ํด๋น ํ์ผ์ด ์ต์ ์ผ๋ก ์ ๋ฐ์ดํธ๋์๋์ง ํ์ธ์ด ๊ฐ๋ฅํ๋ค!
'Git' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Git] src refspec master does not match any ์ค๋ฅ ํด๊ฒฐ ๋ฐ config ์ค์ ํ๊ธฐ (0) | 2021.11.25 |
---|---|
[Git] Git ๋ ํฌ์งํ ๋ฆฌ ์์ฑ ๋ฐ ์ปค๋ฐ (0) | 2021.11.24 |
[Git] Git ์ปค๋ฉ๋(๋ช ๋ น์ด) (0) | 2021.11.24 |
[Git] Git์ ์์ ์์ญ ๋ฐ ํ์ผ ์ํ (0) | 2021.11.24 |
[Git] Git ์ค์นํ๊ธฐ(Windows) (0) | 2021.11.23 |