git bash
๋ก ์ต์ด ์ฐ๊ฒฐ
.git
ํด๋ ์์ฑ ๋ฐ remote ์ ์ฅ์ ์ฐ๊ฒฐ
์ ์ฅ์์ Wiki ํญ๊ณผ ์ฐ๊ฒฐํ๊ณ ์ถ์ ๊ฒฝ์ฐ : https://github.com/ynjch97/YNJCH_WIKI.wiki.git
# global ์ค์
git config --global user.name " [์ด๋ฆ]"
git config --global user.email [์ด๋ฉ์ผ]
# local ์ค์
git config --local user.name " [์ด๋ฆ]"
git config --local user.email [์ด๋ฉ์ผ]
git init
git remote add origin [git ์ฃผ์]
๊ธฐ์กด Github ๊ณ์ ์ฐ๊ฒฐ ํด์ : ์๊ฒฉ ์ฆ๋ช
๊ด๋ฆฌ์ > Windows ์๊ฒฉ ์ฆ๋ช
> ์ ๊ฑฐ
Sign in with a code
ํ์
> ๊ณ์ ๋ก๊ทธ์ธ ์ ์๋ ๋งํฌ๋ก ์ด๋๋จ
git bash ๋ช
๋ น์ด
git remote update
: ๋ฑ๋ก๋ ๋ชจ๋ ์๊ฒฉ ์ ์ฅ์์ ์ ๋ณด๋ฅผ ์ต์ ์ํ๋ก ์
๋ฐ์ดํธ
$ git remote update
gremote: Enumerating objects: 12695, done.
remote: Counting objects: 100% (4/4), done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 12695 (delta 1), reused 3 (delta 1), pack-reused 12691
Receiving objects: 100% (12695/12695), 55.69 MiB | 21.17 MiB/s, done.
Resolving deltas: 100% (2789/2789), done.
From https://github.com/ynjch97/TestProj
* [new branch] TestProjmain -> origin/TestProjmain
* [new branch] TestProjquasar -> origin/TestProjquasar
main
Branch ๋ก๋ถํฐ Pull ๋ฐ๊ณ , Push ํ๊ธฐ
git pull origin main
git add [์ฌ๋ฆด ํ์ผ๋ช
]
git commit -m " [์ปค๋ฐ ๋ฉ์ธ์ง]"
git push -u origin main
Pull = Fetch + Merge
ํน์ Branch์์ Pull : git pull origin [Branch๋ช
]
3-1. ํน์ ํด๋๋ง Pull
https://y00n-lee.tistory.com/39
์ ํํ ํน์ ํด๋ Pull ๋ฐ๋ ์๊ฐ ๋ค๋ฅธ ํด๋ ๋ฐ ํ์ผ๋ค์ ์ฌ๋ผ์ง
Sparse checkout : ์ ์ฅ์์ ํน์ ํด๋๋ ํ์ผ๋ง ๋ณด์ด๋๋ก ํ๋ ๊ธฐ๋ฅ
sparseCheckout ํ์ฑํ : git config core.sparseCheckout true
Pull ๋ฐ๊ณ ์ถ์ ํน์ ํด๋๋ช
์ ํ : echo "[ํด๋๋ช
]" >> .git/info/sparse-checkout
~\.git\info
๊ฒฝ๋ก์ sparse-checkout
ํ์ผ ์์ฑ๋ ๊ฒ ํ์ธ
Pull : git pull origin main
์
๋ก๋ ํ ํ์ผ add : git add [์ฌ๋ฆด ํ์ผ๋ช
]
add ์ด์ ์ผ๋ก ๋์๊ฐ๊ธฐ : git reset HEAD
4-1. ์ญ์ ๋ ํ์ผ Commit
ํ์ ์๋ ํ์ผ ์ ๋ฆฌ๋ฅผ ์ํ ์ต์
-u (์ญ์ ํ ํ์ผ ๋ฐ์ ์)
git add -u [ํ์ผ๋ช
๋๋ * ]
4-2. ๋ฐ์ ์ํ ํ์ธ
Commit : git commit -m "[์ปค๋ฐ ๋ฉ์ธ์ง]"
Push : git push -u origin TestProjmain
5-1. ์์ /์ญ์ ๋ ํ์ผ๋ง Commit
์์ ๋๋ ์ญ์ ๋ ํ์ผ๋ง Commit : ์ต์
-a
ํ์ผ๋ช
์์ ํ ๊ฒฝ์ฐ์๋ add ์ -u
์ต์
์ ๋ฃ์ง ์์ ์ฑ commit ์ -a
์ต์
์ ๋ฃ์ด์ค์ผ ํจ
git commit -a -m " [์ปค๋ฐ ๋ฉ์ธ์ง]"
5-2. ๋๋ฝ๋๋ ํ์ผ ๋ฐ์
.gitignore
์ ๋ฑ๋กํ์ง ์์๋๋ฐ ๋๋ฝ๋ ํ์ผ์ด ์๋ค๋ฉด, git bash
์์ add ์ํ
.gitignore
ํ์ผ ํ์ธํ๊ธฐ : ./.gitignore
์๋ ๋ด์ฉ ํ์ธ๋จ
$ git add TestProj/node_modules
The following paths are ignored by one of your .gitignore files:
TestProj/node_modules
hint: Use -f if you really want to add them.
hint: Turn this message off by running
hint: " git config advice.addIgnoredFile false"
5-2-1. Use -f if you really want to add them
LF will be replaced by CRLF in ํด๊ฒฐ ๋ฐฉ์
git add TestProj/node_modules
๋ช
๋ น์ด ์
๋ ฅ
warning: in the working copy of 'TestProj/node_modules/prettier/esm/parser-postcss.mjs', LF will be replaced by CRLF the next time Git touches it
git config --global core.autocrlf true
๋ช
๋ น์ด ์
๋ ฅ ํ ๋ค์ add
core.autocrlf = true (CRLF > LF ๋ณ๊ฒฝ)
core.autocrlf = false (๊ธฐ๋ณธ ์ค์ , ํ๋ซํผ(OS) ์๊ด์์ด ์ค๋ฐ๊ฟ์ ๋ํ ๋ฌธ์์ด ๊ทธ๋๋ก ์ธ์ํด ์ ์ฅ (๋ฌธ์ ๋ฐ์ ๊ฐ๋ฅ์ฑ ์กด์ฌ))
core.autocrlf = input (LF๋ฅผ line ending์ผ๋ก ์ฌ์ฉ)
# ์ดํ์๋ ๋์ผํ ์ค๋ฅ ๋ฐ์ ์ false ๋ก ๊บผ๋ฒ๋ฆฌ๋ ๋ฐฉ๋ฒ์ด ์๋ค๊ณ ํจ
git config --global core.autocrlf true
git reset HEAD
git add -f TestProj/.quasar/*
git add -f TestProj/node_modules/*
LF(Line-Feed)
Mac, Linux (Unix ๊ณ์ด) ์ค๋ฐ๊ฟ ๋ฌธ์์ด = \n
ASCII ์ฝ๋ = 10
CR(Carriage-Return)
Mac ์ด๊ธฐ ๋ชจ๋ธ ์ค๋ฐ๊ฟ ๋ฌธ์์ด = \r
ASCII ์ฝ๋ = 13
CRLF (Carriage-Return+Line-Feed)
Windows, DOS ์ค๋ฐ๊ฟ ๋ฌธ์์ด = \r\n
CR(\r) + LR(\n) ๋ ๋์์ ํฉ์ณ์ (\r\n)
5-3. Commit Conflict ํด๊ฒฐ
Commit > Pull > Conflict ๋ฐ์ ์
Commit ๊ฑด ์ฐํด๋ฆญ -> Reset -> HARD ์ดํ Commit ๊ฑด์ ๋ค์ Push ํ Pull ๋ฐ์ผ๋ฉด ๋จ
Pull ์ ์ทจ์ํ๋ ค๋ฉด ๋ค์๊ณผ ๊ฐ์ด ์งํ
git reset HEAD^
git fetch --all (remote ์์ค ๋ฐ๊ธฐ)
git checkout origin/staging src/main/webapp/jsp/file_name.jsp (remote ์์ค๋ก overwrite)
git fetch --all
: ๋ชจ๋ ์๊ฒฉ ์ ์ฅ์์ ๋ชจ๋ remote tracking branch๋ฅผ ์
๋ฐ์ดํธ
VSCode > Source Control > Pull, Push > Git Fetch From All Remotes
์๊ฒฉ ์ ์ฅ์์ ๋ก์ปฌ์ Branch ํ์ธ
# Branch ํ์ธ
git branch
# Branch ์์ธ ํ์ธ
git branch -v
# ์๊ฒฉ ์ ์ฅ์ Branch ํ์ธ
git branch -r
7-1. Branch ์์ฑ ๋ฐ ์ด๋
# ํน์ Branch ๋ก ์ด๋
git checkout [๋ธ๋์น๋ช
]
# Branch ์์ฑ ๋ฐ ํด๋น Branch ๋ก ์ด๋
git checkout -b [๋ธ๋์น๋ช
]
# ์๊ฒฉ ์ ์ฅ์ Remote Branch ์ ์์ฑ
git push origin [๋ธ๋์น๋ช
]
# master Branch์์ Branch ์์ฑ
git branch [๋ธ๋์น๋ช
] master
# Local ๊ณผ ์๊ฒฉ ์ ์ฅ์ Branch ์ฐ๋
git branch --set-upstream-to origin/[Branch๋ช
]
# ๋ก์ปฌ Branch ์ญ์
git branch -D [๋ธ๋์น๋ช
]
# ์๊ฒฉ Branch ์ญ์
git push origin --delete [๋ธ๋์น๋ช
]
Git Branch ๋ฅผ ๋ค๋ฅธ Branch ๋ก ํฉ์น๋ ๊ณผ์
TestProjynjch
Source Control > ยทยทยท
> Branch > Merge Branch > orgin/TestProjmain
Push (Sync Changes ๋ฒํผ) ์ํ
git bash ๋ช
๋ น์ด
# ํด๋น Branch์ merge
git merge TestProjmain
git push -u origin TestProjynjch
8-1. Branch ์ main ์์ค Merge ํ๊ธฐ
Merge ํ ๋ ์ถฉ๋ ๋ฐ์ ์, diff Tool ์ ์ด์ฉํ์ฌ ๋น๊ต (WinMerge)
# main ์ผ๋ก ์ด๋
git checkout main
# ํด๋น Branch์ main ์ merge
git merge [๋ธ๋์น๋ช
]
8-2. ๋ค๋ฅธ Branch ์ปค๋ฐ ๋ด์ฉ์ ๋ด Branch ์ ๊ฐ์ ธ์ค๊ธฐ
git cherry-pick
: ๋ค๋ฅธ Branch์ ์๋ ์ปค๋ฐ์ ์ ํ์ ์ผ๋ก ๋ด Branch์ ์ ์ฉ์ํฌ ๋ ์ฌ์ฉํ๋ ๋ช
๋ น์ด
Branch Y์ ์ปค๋ฐ ์ค 76ae30ef์ 13af32cc ๋ง ๊ณจ๋ผ ํ์ฌ Branch์ธ X์ ์ ์ฉ
git cherry-pick 76ae30ef 13af32cc
conflict ๋ฐ์ ์ ๋ค์ ๋ช
๋ น์ด ์คํ
# Conflict๋ฅผ ํด๊ฒฐํ๊ณ cherry-pick์ ์งํ์ํจ๋ค.
git cherry-pick --continue
# cherry-pick์ ์ค๋จํ๊ณ ์ด์ ์ํ๋ก ๋๋์๊ฐ๋ค.
git cherry-pick --abort
merge commit์ cherry-pick ํ ๋
git cherry-pick -m 1 < merge_commit_hash>
8-3. test Branch์์ ์์
ํ ๊ฒ ์ค ํน์ ํ์ผ๋ง master ์ ๋ฐ์์ํค๊ธฐ
git checkout test
git pull
git checkout master
git pull
git checkout origin/test src/main/java/com/ynjch/petmily/controller/user/UserControllor.java
git commit -m " [์ปค๋ฐ ๋ฉ์ธ์ง]"
git push -u origin master
8-4. test Branch์์ ์์
ํ ๊ฒ ์ค ํน์ ์ปค๋ฐ๋ง master ์ ๋ฐ์์ํค๊ธฐ
git checkout test
git pull
git checkout master
git cherry-pick 584a586
git commit -m " [์ปค๋ฐ ๋ฉ์ธ์ง]"
git push -u origin master
.git
์ด ์๋ ์ต์์ ๊ฒฝ๋ก์ .gitignore
ํ์ผ ์์ฑ
# .gitignore ํ์ผ ์์ฑ
TestProj /node_modules
TestProj /.quasar
.gitignore
์๋์ ๊ฐ์ด ํ์ธ ๊ฐ๋ฅ
$ ./.gitignore
./.gitignore: line 3: TestProj/node_modules: Is a directory
./.gitignore: line 4: TestProj/.quasar: Is a directory
9-1. ์บ์ ์ญ์ ์ฒ๋ฆฌ
Repository์ ์ด๋ฏธ ํ์ผ๋ค์ด ํฌํจ๋์ด ์์ผ๋ฉด .gitignore ์ ์ฉ์ด ์๋ ์ ์์
์๋ git bash ์บ์ ์ญ์ ๋ช
๋ น์ด๋ฅผ ํตํด ํด๊ฒฐ
git rm -r --cached .
git add .
git commit -m " Untrack files in .gitignore"
git push -u origin TestProjynjch
๋ฆด๋ฆฌ์ฆ ๋ฒ์ ๋ฑ ์์ค์ฝ๋์ ํน๋ณํ ๋ฒ์ ์ ๊ธฐ๋กํ๋ ๋ฐ์ ์ฌ์ฉ
Git Tag ๊ด๋ จ ๋ช
๋ น์ด ์ ๋ฆฌ ๋งํฌ
Tag ์ ํ
Lightweight : ํน์ ์ปค๋ฐ์ ๋ํ ํฌ์ธํฐ ์ญํ ๋ง ์ํ
Annotated : Git ๋ฐ์ดํฐ๋ฒ ์ด์ค์ ์์ ํ ๊ฐ์ฒด๋ก ์ ์ฅ๋์ด ํ๊ทธํ ์ฌ๋์ ์ด๋ฆ๊ณผ ์ด๋ฉ์ผ, ๋ ์ง, ํ๊ทธ ๋ฉ์์ง ๋ฑ์ ํจ๊ป ์ ์ฅ
์์ ๊ฐ์ด v1.0.0
Tag ๋ฅผ ์ถ๊ฐํ๋ฉด ~/releases/tag/v1.0.0
๊ฒฝ๋ก์์ ๊ด๋ จ ๋ด์ฉ ํ์ธ ๊ฐ๋ฅ
11-1. ์๋ณธ ์ ์ฅ์์ ๋๊ธฐํ
Forkํ ์ ์ฅ์๋ origin
์ผ๋ก, ์๋ณธ ์ ์ฅ์๋ upstream
์ผ๋ก ์ ์ฅ์ ๋ฑ๋ก
git remote add upstream https://github.com/ynjch97/Stockid.git
git remote add origin https://github.com/KMJHere/Stockid.git
๋์ ์๊ฒฉ ์ ์ฅ์ ์์ค pull ๋ฐ main Branch ์ ํ
git pull origin main
git checkout main
์๋ณธ ์ ์ฅ์์ ๋๊ธฐํ ๋ฐ ๋์ ์ ์ฅ์์ merge
git fetch upstream main
git merge upstream/main
11-2. ์๋ณธ ์ ์ฅ์์ Pull Request
๋ก์ปฌ ์ ์ฅ์์์ commit ๋ฐ push
GitHub > ๋์ Repository > New pull request
์๋ณธ Repository์ Branch ์ ํ ๋ฐ ๋์ Repository Branch ์ ํ ํ Pull Request
์๋ฝ์ด ๋๋ฉด ์์ ๋๊ธฐํ ๊ณผ์ ๋ฐ๋ณต
์ฐธ๊ณ https://andamiro25.tistory.com/193
Git Repository ์ ์์ค ์ปค๋ฐํ๊ธฐ
Pull ๋ฐ์ ํ Git Staging ์์ Commit
ํ๋ก์ ํธ ์ฐํด๋ฆญ > Team > Push Branch Staging
Team > Pull
13-1. ํ์ฅ ํ๋ก๊ทธ๋จ
Commit Message Editor : ์๋ํฐ ์ฐฝ์์ ์ปค๋ฐ ๋ด์ฉ์ ์์ฑํ ์ ์์
Git Graph : GIT ๊ทธ๋ํ ๋ฐ ํ์ผ Diff
๊ฐ์ Branch ๋ด ์ฐจ์ด์ ์ View Diff with Working File
์ผ๋ก ํ์ธํ๋ ๊ฒ์ด ๋ณด๊ธฐ ํธ๋ฆฌ
Git History : ๊ฐ๋ณ ํ์ผ์ ๋ํ ํ์คํ ๋ฆฌ ๋ด์ญ์ ์กฐํ
๊ฐ ํ์ผ์ ์ฐํด๋ฆญ > Git: View File History
์
๋ก๋ ํ ํ์ผ add : Source Control > Changes to Staged Changes