1. Local Repository ์์ฑ
$ git init
ํ์ฌ ๋๋ ํ ๋ฆฌ์ git ์ ์ฅ์๋ฅผ ์์ฑํ๋ค.
# ํ์ฌ ๋๋ ํ ๋ฆฌ์ ์ด๋ฆ์ด `project1`์ธ ์ ์ฅ์ ๋ง๋ค๊ธฐ
$ git init project1
# `mydir` ๋๋ ํ ๋ฆฌ ์์ ์ด๋ฆ์ด `hello`์ธ ์ ์ฅ์ ๋ง๋ค๊ธฐ
$ cd mydir
$ git init hello
# `./mydir/world` ๋๋ ํ ๋ฆฌ๋ฅผ ์ ์ฅ์๋ก ๋ง๋ค๊ธฐ
$ git init ./mydir/world
โ
2. Remote Repository ์์ฑ
๊นํ๋ธ, ๋น๋ฒํท, ๊น๋ฉ๋ฑ์ ๊นํธ์คํ ์ ์ฒด๋ฅผ ํตํด Remote Repository๋ฅผ ์์ฑํ๋ค.
$ git remote add origin https://github.com/your/repository
# origin: ์๊ฒฉ์ ์ฅ์ ์ฃผ์์ ๋๋ช
์ฌ. ๋งค๋ฒ ์ฃผ์๋ฅผ ์
๋ ฅํ๋ ๊ฒ์ด ๋ฒ๊ฑฐ๋กญ๊ธฐ ๋๋ฌธ์ origin์ผ๋ก ๋์ฒดํ๋ค.
$ git remote set-url origin https://github.com/your/repository
# set-url: remote์ฃผ์๋ฅผ ์๋ชป์ณค๋ค๋ฉด ์์ ํ๋ค.
$ git remote show origin
# show origin:
3. git config ์ค์
git config --global user.name "ABC"
git config --global user.email "ABC@DEF.com"
- ์ฒ์ push๋ฅผ ํ๋ค๋ฉด, git config๋ช ๋ น์ด๋ฅผ ํตํด ์ด๋ฉ์ผ๊ณผ ๋น๋ฐ๋ฒํธ๋ฅผ ๋ฑ๋กํ๋ค.
- ๋น๋ฐ๋ฒํธ๋ฅผ ํ์ดํํ ๋๋ ์ถ๋ ฅ์ด ๋์ง ์์ผ๋ฏ๋ก ๊ทธ๋ฅ ์ ๋ ฅํ๋ฉด ๋๋ค.
โ
4. git add
$ gid add .
// ๋ณ๊ฒฝ๋ ๋ชจ๋ ํ์ผ์ local repository์ ์ถ๊ฐ
$ git add --update
// ํ์ฌ ๊น์ด ์ถ์ ํ๊ณ ์๋ ํ์ผ๋ง add
$ git add *.txt
// ๋ชจ๋ txt ํ์ผ์ add
$ git add Documents/coding/*/
// ๋๋ ํ ๋ฆฌ์ ๋ํด์๋ ์ฌ์ฉํ ์ ์๋ค
5. git commitโ
$ git commit ๋ช
๋ น์ด
$ git commit -m "๋ฉ์ธ์ง ๋ด์ฉ"
// vi์์ ๋ณ๋์ ๋ฉ์ธ์ง๋ฅผ ์์ฑํ์ง ์๊ณ ์ธ๋ผ์ธ ํ์์ผ๋ก ๋ฐ๋ก ์ปค๋ฐ ๋ฉ์ธ์ง๋ฅผ ์์ฑํ๊ธฐ ์ํ ์ต์
$ git commit -a [ํ์ผ๋ช
]
// "์์ ํ ํ์ผ"์ ๋ํด add๋ฅผ ์ํํ๋ ์ต์
// ์๋ก๋ง๋ ํ์ผ์ด ์์ผ๋ฉด ๋ฐ๋ก add๋ฅผ ํด์ผํ๋ค.
$ git commit -am "๋ฉ์ธ์ง"
// a์ต์
๊ณผ m์ต์
์ ํฉ์ณ์ ์ฌ์ฉํ๋ ์ต์
$ git commit --ammend -m "commit_message"
# ๋ง์ง๋ง commit ๋ฉ์์ง ์์ ํ๊ธฐ
$ git reset HEAD^
# ๋ฐ๋ก ์ด์ commit์ผ๋ก ๋๋๋ฆฌ๊ธฐ (๋ฐฉ๊ธํ ์ปค๋ฐ ์ทจ์)
$ cd food_list
$ git add .
$ git branch food/cost
$ git branch food/feedback
$ git checkout food/cost
$ git commit -m "cost" food_cost.txt
$ git checkout food/feedback
$ git commit -m "feedback" food_feedback.txt
master ๋ธ๋์น์ ๋ชจ๋ ํ์ผ์ addํ ํ์ ํน์ branch์์ ํน์ ํ์ผ๋ง ์ปค๋ฐํ ์ ์๋ค.
6. git push
$ git push { ์๊ฒฉ์ ์ฅ์ ์ด๋ฆ } { ์๊ฒฉ ๋ธ๋์น ์ด๋ฆ }
$ git push origin master
# remote repository๋ฅผ ์์ฑํ๋ฉด ๊ธฐ๋ณธ์ ์ผ๋ก master๋ผ๋ ์ด๋ฆ์ ๋ธ๋์น๊ฐ ์์ฑ๋๋ค.
$ git push origin { ๋ธ๋์น ์ด๋ฆ }
# ๋ค๋ฅธ branch๋ก push ํ๊ณ ์ถ์ผ๋ฉด ๋ฅผ ํน์ ๋ธ๋์น๋ช
์ผ๋ก ๋ฐ๊พผ๋ค.
$ git push -u { ์๊ฒฉ ์ ์ฅ์ ๋ณ๋ช
} { ๋ก์ปฌ ๋ธ๋์น๋ช
}
# ์ดํ์ git push ๋ช
๋ น์ด๋ง ์
๋ ฅํด๋ ์๊ฒฉ ์ ์ฅ์๋ก push ํ ์ ์๊ฒ ๋ฉ๋๋ค.
git push --delete { ์๊ฒฉ ๋ธ๋์น๋ช
}
# remote repository์ ์๋ ๋ธ๋์น๋ฅผ ์ญ์ ํฉ๋๋ค.
-u ์ต์ : master ๋ผ๋ ํ์ฌ ๋ธ๋์น๋ฅผ ์๋์ผ๋ก origin ์ด๋ผ๋ ์๊ฒฉ์ ์ฅ์์ master ๋ธ๋์น๋ก ์ฐ๊ฒฐํด ๊ฐ๋จํ git push ๋ง ์ ๋ ฅํ์ฌ ๋ฐ์ํ๊ฑฐ๋ git pull ์ ์ ๋ ฅํ ๋ origin์ด๋ผ๋ ์๊ฒฉ์ ์ฅ์์ master ๋ธ๋์น๋ฅผ ๋ก์ปฌ ์ ์ฅ์์ master ๋ธ๋์น๋ก merge ํ ์ ์๊ฒ ํด์ฃผ๊ฒ ๋ค๋ ์๋ฏธ์ด๋ค. ์๊ฒฉ์ ์ฅ์์ ๋ก์ปฌ ์ ์ฅ์๋ฅผ ์๋ ์ฐ๊ฒฐํ์ฌ ์ฌ์ฉํ ์ ์๋ค.
- push ํ๊ธฐ ์ ์ Local Repo๋ ํญ์ Remote Repo์ ์ต์ ๋ฒ์ ์ ์ ์งํด์ผ ํ๋ค.
- Remote Repo์ ์กด์ฌํ๋ ์ปค๋ฐ์ด Local Repo์ ์์ผ๋ฉด ์๋ฌ๊ฐ ๋ฐ์ํ๋ค.
โโ
7. ์์ฃผ ์ฌ์ฉํ๋ ์ฝ๋
git init
git remote add orgin master
git config
git add .
git commit -m "Initial Commit"
git push origin master
git add .
git commit -m "๋ฉ์์ง ๋ด์ฉ"
git push origin {๋ธ๋์น๋ช
}
'๐ DevOps > ๐ฅ GIT' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
GIT ์๊ฒฉ ์ ์ฅ์ ๋ช ๋ น์ด: branch, merge, checkout, push (0) | 2021.10.13 |
---|---|
[GIT] ๋ค๋ฅธ ์์ด๋ ์ฌ์ฉ์, "remote: Permission to ์๋ฌ" (์๋์ฐ) (0) | 2021.02.14 |
[GIT] ์์ฃผ ๋ฐ์ํ๋ ERROR ๋ชจ์ (0) | 2021.01.28 |
์๋ก์ด ๋ก์ปฌํ๊ฒฝ์์ ์์ ํ ๊ฒฝ์ฐ (0) | 2021.01.26 |
[GIT] ์ ๋ฌธ, ๊ตฌ์กฐ, ์๋ ์์์ ๋ํด ์์๋ณด์ (0) | 2021.01.26 |