git init
ํ์ฌ ํด๋๋ฅผ git์ผ๋ก ๊ด๋ฆฌํ๋๋ก ํ๋ค == ์ด๊ธฐํ
์คํํ๋ฉด ์จ๊ฒจ์ง ํด๋๋ก .git ํด๋๋ฅผ ๋ณผ ์ ์๋ค.
~/Desktop/git $ git init Initialized empty Git repository in C:/Users/qkrwl/Desktop/git/.git/ ~/Desktop/git (main) $ ls -al total 8 drwxr-xr-x 1 qkrwl 197609 0 12์ 30 21:23 ./ drwxr-xr-x 1 qkrwl 197609 0 12์ 30 21:22 ../ drwxr-xr-x 1 qkrwl 197609 0 12์ 30 21:23 .git/
git config
github์ ์ฐ๊ฒฐ์ ์ํ ์ค์ ์ ํ๋ค.
~/Desktop/git (main) $ git config --global user.email '์ด๋ฉ์ผ' ~/Desktop/git (main) $ git config --global user.name '์ด๋ฆ'
์ค์ ํ ๊ฐ์ ๋ณผ ์๋ ์๋ค.
~/Desktop/git (main) $ git config --global --list user.email='์ด๋ฉ์ผ' user.name='์ด๋ฆ' ...
git add [file|folder]
|git restore --staged [file|folder]
์ฐ๊ฒฐ๋ ๋ ํฌ์งํ ๋ฆฌ์ ์ฌ๋ฆด ํ์ผ์ ์ถ๊ฐ | ์ญ์ ํ๋ค.
ํ์ผ๋ช ์ด๋ ํด๋๋ช ์ ์ฌ์ฉํด ์ ํ์ ์ผ๋ก ๋ฑ๋ก|ํด์ ํ ์ ์๋ค.
git add .
๊ณผ ๊ฐ์ด ํ์ฌ ๋๋ ํ ๋ฆฌ ์ ์ฒด๋ฅผ ํ๋ฒ์ ๋ฑ๋กํ ์ ์๋ค.
- ๊ตฌ๋ฒ์ ์์๋ restore๋์
git reset HEAD [file|folder]
๋ก ์ด๋ค.
- ์ถ๊ฐ
~/Desktop/git (main) $ echo 'hello Git world' > sample.txt ~/Desktop/git (main) $ ls sample.txt ~/Desktop/git (main) $ git add sample.txt
- ์ ๊ฑฐ
~/Desktop/git (main) $ git restore --staged sample.txt ~/Desktop/git (main) $ git reset HEAD sample.txt
git status
git์ด ๊ด๋ฆฌํ๊ณ ์๋ ํ์ผ๊ณผ ํด๋์ ๋ํด์ ์ ๋ณด๋ฅผ ํ์ํ๋ค.
- ์ถ๊ฐ๋ ๊ฒฝ์ฐ
~/Desktop/git (main) $ git status On branch main No commits yet Changes to be committed: (use "git rm --cached <file>..." to unstage) new file: sample.txt
- ์์ง ์ถ๊ฐ๋์ง ์์ ๊ฒฝ์ฐ
~/Desktop/git (main) $ git status On branch main Untracked files: (use "git add <file>..." to include in what will be committed) temp.txt nothing added to commit but untracked files present (use "git add" to track)
- ์์ ๋ ๊ฒฝ์ฐ
~/Desktop/git (main) $ git status On branch main Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git restore <file>..." to discard changes in working directory) modified: sample.txt no changes added to commit (use "git add" and/or "git commit -a")
- ์ถ๊ฐ๋ ๊ฒฝ์ฐ
git commit -m [message]
git add/restore
๋ฅผ ํตํด ์ถ๊ฐ/์ญ์ ๋ ํ์ผ๋ค์ ํ๋์ ๊ธฐ๋ก์ผ๋ก ์ ์ฅํ๋ค.~/Desktop/git (main) $ git commit -m '[ADD] sample.txt' [main (root-commit) d1d23e4] [ADD] sample.txt 1 file changed, 1 insertion(+) create mode 100644 sample.txt
git log (branch)
git commit
์ ํตํด ๋จ๊ฒจ์ง ๊ธฐ๋ก๋ค์ ๊ด๋ฆฌํ๋ค.~/Desktop/git (main) $ git log commit d1d23e4e78e88d82a71a43dad2b3d8b33b2d9a04 (HEAD -> main) Author: JissuPark <qkrwltn9412@gmail.com> Date: Wed Dec 30 22:59:50 2020 +0900 [ADD] sample.txt
๋๋ฌด ๊ธธ๋ค๋ฉด ํ ์ค๋ก ๋ณผ์ ์๋ ์ต์ ์ ์ฌ์ฉํ๋ค.
--oneline
~/Desktop/git (main) $ git log --oneline d1d23e4 (HEAD -> main) [ADD] sample.txt
์ ์ฒด์ ์ธ ํ๋ฆ์ ๋ณด๊ณ ์ถ๋ค๋ฉด ๊ทธ๋ํ ์ต์ ์ ์ฌ์ฉํ๋ค.
--graph
ํด๋น ์ต์ ์ commit ์๊ฐ ๋ง๊ณ branch๊ฐ ์๋ค๋ฉด ๋์ฑ ๋น์ ๋ฐํ๋ค.
~/Desktop/git (main) $ git log --oneline --graph * d1d23e4 (HEAD -> main) [ADD] sample.txt
git remote add [repository] [github_url]
์๊ฒฉ ๋ ํฌ์งํ ๋ฆฌ์ ์ฐ๊ฒฐ์ ๋ด๋นํ๋ค.
~/Desktop/git (main) $ git remote add upstream https://github.com/JissuPark/Git.git
-v
์ต์ ์ ํตํด ๋ฑ๋ก๋ ๋ ํฌ์งํ ๋ฆฌ๋ฅผ ํ์ธํ๋ค.~/Desktop/git (main) $ git remote -v upstream https://github.com/JissuPark/Git.git (fetch) upstream https://github.com/JissuPark/Git.git (push)
git push [repository] [branch]
[branch]์ commit๋ ๊ธฐ๋ก๊ณผ ํจ๊ป ํ์ผ๋ค์ ์๊ฒฉ [repository]๋ก ์ ์กํ๋ค. == ํ์ผ ์ฌ๋ฆฌ๊ธฐ
- repository :
git remote
๋ฅผ ํตํด์ ์ค์ ํ ๋ณ์นญ
- branch : ๋ก์ปฌ์์ ์ฌ์ฉํ๊ณ ์๋ ๋ธ๋์น๋ช
~/Desktop/git (main) $ git push upstream main Enumerating objects: 3, done. Counting objects: 100% (3/3), done. Writing objects: 100% (3/3), 243 bytes | 121.00 KiB/s, done. Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 To https://github.com/JissuPark/Git.git * [new branch] main -> main
- repository :
git pull [repository] [branch]
[repository]์ ์๋ ํ์ผ๋ค์ [branch]๋ก ์ ์กํ๋ค. == ํ์ผ ๋ด๋ ค๋ฐ๊ธฐ
~/Desktop/git (main) $ git pull upstream main remote: Enumerating objects: 5, done. remote: Counting objects: 100% (5/5), done. remote: Compressing objects: 100% (2/2), done. remote: Total 3 (delta 1), reused 0 (delta 0), pack-reused 0 Unpacking objects: 100% (3/3), 711 bytes | 44.00 KiB/s, done. From https://github.com/JissuPark/Git * branch main -> FETCH_HEAD 2ec5d53..8052b60 main -> upstream/main hint: Waiting for your editor to close the file... [main 2020-12-30T15:52:33.121Z] update#setState idle Merge made by the 'recursive' strategy. Git_Basic.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
Uploaded by Notion2Tistory v1.1.0