git config --global user.name <username>
git config --global user.email <email>
CRLF _ window 사용자의 경우
git config --global core.autocrlf true
Editor
git config --global core.editor vim
전체 설정 확인
git config --list
항목별 설정 확인
git config <key>
Repository
Check out
Stage
Commit
Tag
Push
Pull
Branch
Merge
Workspace 생성
mkdir git_ws
Working Dorectory 생성
cd git_ws
git_ws mkdir test_project
Git init
git init
하는 순간 이 폴더는 Repository가 됨 (Git이 Working Dorectory로 인식했다는 말)git init
파일 생성
test_project % touch test.txt
test_project % ls
test.txt
Git Status
git status
Git Add
git add <filename>
Git Commit
git commit -m "commit 에 대한 설명" <filename>
파일 생성
PC@DESKTOP-7USISEH MINGW64 ~
$ cd Documents/
PC@DESKTOP-7USISEH MINGW64 ~/Documents
$ mkdir git_ws
Git init
PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws
$ mkdir test_project
PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws
$ cd test_project
PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws/test_project
$ git init
Initialized empty Git repository in C:/Users/PC/Documents/git_ws/test_project/.git/
PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws/test_project (master) 📌관리하기 시작했다는 뜻
결과
text 파일 생성
git status
PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws/test_project (master)
$ git status
On branch master
No commits yet
Untracked files:
(use "git add <file>..." to include in what will be committed)
test.txt
nothing added to commit but untracked files present (use "git add" to track)
PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws/test_project (master)
$ git add test.txt
PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws/test_project (master)
$ git commit -m 'first commit' test.txt
[master (root-commit) 82b296c] first commit
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 test.txt
Local Resository에 연동할 Remote Repository를 등록 (Token 사용)
git remote add origin http://<username>:<token>@github.com/<repository>.git
PC@DESKTOP-7USISEH MINGW64 ~
$ cd Documents/
PC@DESKTOP-7USISEH MINGW64 ~/Documents
$ cd git_ws/
PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws
$ cd test_project/
PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws/test_project (master)
$ git remote add origin https://JaeminOh94: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@github.com/JaeminOh94/test_project.git
정보 확인
PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws/test_project (master)
$ git remote -v
origin https://JaeminOh94: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@github.com/JaeminOh94/test_project.git (fetch)
origin https://JaeminOh94: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@github.com/JaeminOh94/test_project.git (push)
LR(HEAD)에 즉, commit 까지 한 내용(반영된 변경내용)을
Remote Repository 에도 반영하기 위해 Git Push 사용
간단히 말하면,
내가 만든 파일을 업로드 하는(=반영) 명령어
Git Push
git push origin <branchname>
실습
PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws/test_project (master)
$ git push origin master
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Writing objects: 100% (3/3<), 210 bytes | 210.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
To https://github.com/JaeminOh94/test_project.git
* [new branch] master -> master
RR의 내용에 맞춰 LR을 갱신하려면 Git Pull 사용
간단히 말해,
LR(Github online)에서 작업해서 RR(PC file)로 가져오는 것
.md : mark down의 약자, 마크다운 문법을 사용
Git Pull
git pull origin <brnachname>
위치 : git_ws
이름 : exam_project
PC@DESKTOP-7USISEH MINGW64 ~
$ cd Documents/git_ws/
PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws
$ mkdir exam_project
PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws
$ cd exam_project/
파일 : exam.txt
Index 추가
HEAD 등록
PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws/exam_project
$ touch exam.txt
PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws/exam_project
$ git init
Initialized empty Git repository in C:/Users/PC/Documents/git_ws/exam_project/.git/
PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws/exam_project (master)
$ git add exam.txt
PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws/exam_project (master)
$ git status
On branch master
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: exam.txt
PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws/exam_project (master)
$ git commit -m 'add exam.txt' exam.txt
[master (root-commit) 44fecca] add exam.txt
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 exam.txt
PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws/exam_project (master)
$ git status
On branch master
nothing to commit, working tree clean
(서로 연결) exam_project의 Local Repository에 앞서 생성한 remote repository 등록 후 확인
token은 앞서 생성한 token 사용
PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws/exam_project (master)
$ git remote add origin https://JaeminOh94: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@github.com/JaeminOh94/exam_project.git
PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws/exam_project (master)
$ git remote -v
origin https://JaeminOh94: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@github.com/JaeminOh94/exam_project.git (fetch)
origin https://JaeminOh94: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@github.com/JaeminOh94/exam_project.git (push)
commit 항목을 RR에 반영
RR에서 exam.txt 확인
PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws/exam_project (master)
$ git push origin master
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Writing objects: 100% (3/3), 213 bytes | 213.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
To https://github.com/JaeminOh94/exam_project.git
* [new branch] master -> master
PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws/exam_project (master)
$ git status
On branch master
nothing to commit, working tree clean
exam.txt 파일 수정 : This is git exam
(참고>파일 수정하는 방법)
PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws/exam_project (master)
$ cat exam.txt
PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws/exam_project (master)
$ git pull origin master
remote: Enumerating objects: 5, done.
remote: Counting objects: 100% (5/5), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), 637 bytes | 127.00 KiB/s, done.
From https://github.com/JaeminOh94/exam_project
* branch master -> FETCH_HEAD
44fecca..18e125f master -> origin/master
Updating 44fecca..18e125f
Fast-forward
exam.txt | 1 +
1 file changed, 1 insertion(+)
PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws/exam_project (master)
$ cat exam.txt
This is git exam
Commit 1
PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws/exam_project (master)
$ touch exam2.txt
PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws/exam_project (master)
$ git status
On branch master
Untracked files:
(use "git add <file>..." to include in what will be committed)
exam2.txt
nothing added to commit but untracked files present (use "git add" to track)
PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws/exam_project (master)
$ git add exam2.txt
PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws/exam_project (master)
$ git status
On branch master
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
new file: exam2.txt
PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws/exam_project (master)
$ git commit -m 'commit 1' exam2.txt
[master cb67b82] commit 1
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 exam2.txt
PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws/exam_project (master)
$ git status
On branch master
nothing to commit, working tree clean
PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws/exam_project (master)
$ git push origin master
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Delta compression using up to 8 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 264 bytes | 264.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
To https://github.com/JaeminOh94/exam_project.git
18e125f..cb67b82 master -> master
Commit 2
PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws/exam_project (master)
$ git pull origin master
remote: Enumerating objects: 5, done.
remote: Counting objects: 100% (5/5), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), 660 bytes | 132.00 KiB/s, done.
From https://github.com/JaeminOh94/exam_project
* branch master -> FETCH_HEAD
cb67b82..6a55abe master -> origin/master
Updating cb67b82..6a55abe
Fast-forward
exam2.txt | 1 +
1 file changed, 1 insertion(+)
PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws/exam_project (master)
$ cat exam2.txt
This is git exam2
Commit 3
PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws/exam_project (master)
$ cat > exam3.txt
This is git exam3.
PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws/exam_project (master)
$ cat exam3.txt
This is git exam3.
PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws/exam_project (master)
$ git status
PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws/exam_project (master)
$ git add exam3.txt
PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws/exam_project (master)
$ git status
PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws/exam_project (master)
$ git commit -m 'commit 3' exam3.txt
PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws/exam_project (master)
$ git status
PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws/exam_project (master)
$ git push origin master
누군가가 올려놓은 파일에 접속을 해서 Local로 COPY한 다음에 연동해서 작업하는 연습
Branch 설정 변경
LR을 생성하지 않은 상태에서
Git Clone 명령을 사용해 RR을 Local에 복제 가능
Git Clone
git clone https://<username>:<token>@github.com/<repository>.git
PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws
$ git clone https://JaeminOh94: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@github.com/JaeminOh94/HelloGit.git
Cloning into 'HelloGit'...
remote: Enumerating objects: 4, done.
remote: Counting objects: 100% (4/4), done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 4 (delta 0), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (4/4), done.
PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws
$ ls
HelloGit/ exam_project/ test_project/
💡 Local → Remote : git add commit push
💡 Remote → Local : git pull
(ㄱ) Local
Local Branch 조회
git branch
Remote Branch 조회
git branch -r
Local + Remote Branch 조회
git branch -a
Branch 생성
git branch <branch name>
Branch 이동
git checkout <branch name>
Branch 생성 + 이동
git checkout -b <branch name>
(ㄴ) Remote
git push origin <branch name>
(ㄷ) 삭제
git branch -d <branch name>
💡 Local → Remote : git add commit push
💡 Remote → Local : git pull
Local
PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws/HelloGit (master)
$ git branch -r
origin/HEAD -> origin/master
origin/master
Local + Remote
PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws/HelloGit (master)
$ git branch -a
* master
remotes/origin/HEAD -> origin/master
remotes/origin/master
Local
PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws/HelloGit (master)
$ git branch branch01
PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws/HelloGit (master)
$ git branch
branch01
* master ←💡여기가 활성화 되어 있음
Remote (작업한 것을 알려주는 단계)
PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws/HelloGit (branch02)
$ git push origin branch01
Total 0 (delta 0), reused 0 (delta 0), pack-reused 0
remote:
remote: Create a pull request for 'branch01' on GitHub by visiting:
remote: https://github.com/JaeminOh94/HelloGit/pull/new/branch01
remote:
To https://github.com/JaeminOh94/HelloGit.git
* [new branch] branch01 -> branch01
PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws/HelloGit (branch02)
$ git push origin branch02
Total 0 (delta 0), reused 0 (delta 0), pack-reused 0
remote:
remote: Create a pull request for 'branch02' on GitHub by visiting:
remote: https://github.com/JaeminOh94/HelloGit/pull/new/branch02
remote:
To https://github.com/JaeminOh94/HelloGit.git
* [new branch] branch02 -> branch02
Local
PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws/HelloGit (master)
$ git checkout branch01
Switched to branch 'branch01'
PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws/HelloGit (branch01) ←💡바뀜
$ git branch
* branch01 ←💡여기가 활성화 되어 있음
master
PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws/HelloGit (branch01)
$ git checkout -b branch02
Switched to a new branch 'branch02'
Local
PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws/HelloGit (branch02)
$ git checkout master
PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws/HelloGit (master)
$ git branch
branch01
branch02
* master
PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws/HelloGit (master)
$ git branch -d branch02
Deleted branch branch02 (was de9a397).
PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws/HelloGit (master)
$ git branch
branch01
* master
PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws/HelloGit (master)
$ git branch -d branch01
Deleted branch branch01 (was de9a397).
PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws/HelloGit (master)
$ git branch
* master
PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws/HelloGit (master)
$ git branch -a
* master
remotes/origin/HEAD -> origin/master
remotes/origin/branch01
remotes/origin/branch02
remotes/origin/master
Remote
PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws/HelloGit (master)
$ git push origin --delete branch02
To https://github.com/JaeminOh94/HelloGit.git
- [deleted] branch02
PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws/HelloGit (master)
$ git push origin --delete branch01
To https://github.com/JaeminOh94/HelloGit.git
- [deleted] branch01
PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws/HelloGit (master)
$ git branch -a
* master
remotes/origin/HEAD -> origin/master
remotes/origin/master
위치 : git_ws
생성 확인
📌상위 폴더로 이동
PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws/HelloGit (master)
$ cd ..
📌Clone 작업
PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws
$ git clone https://JaeminOh94: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@github.com/JaeminOh94/branch_project.git
Cloning into 'branch_project'...
remote: Enumerating objects: 4, done.
remote: Counting objects: 100% (4/4), done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 4 (delta 0), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (4/4), done.
📌branch_project 연결
PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws
$ cd branch_project/
📌생성 확인
PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws/branch_project (main)
$ ls -all
total 13
drwxr-xr-x 1 PC 197121 0 Jan 2 02:05 ./
drwxr-xr-x 1 PC 197121 0 Jan 2 02:05 ../
drwxr-xr-x 1 PC 197121 0 Jan 2 02:05 .git/
-rw-r--r-- 1 PC 197121 3238 Jan 2 02:05 .gitignore
-rw-r--r-- 1 PC 197121 16 Jan 2 02:05 README.md
이름 : branch01, branch02
이동 : branch01
확인 : Local Branch 목록 (현재 Branch 위치-branch01)
📌 생성
PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws/branch_project (main)
$ git branch branch01
PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws/branch_project (main)
$ git checkout -d branch02
fatal: git checkout: --detach does not take a path argument 'branch02'
📌 이동
PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws/branch_project (main)
$ git checkout branch01
Switched to branch 'branch01'
📌 확인
PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws/branch_project (branch01)
$ git branch
* branch01
branch02
main
Push : branch01, brnach02
확인 : Remote Branch 목록, Github
PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws/branch_project (branch02)
$ git push origin branch01
Total 0 (delta 0), reused 0 (delta 0), pack-reused 0
remote:
remote: Create a pull request for 'branch01' on GitHub by visiting:
remote: https://github.com/JaeminOh94/branch_project/pull/new/branch01
remote:
To https://github.com/JaeminOh94/branch_project.git
* [new branch] branch01 -> branch01
PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws/branch_project (branch02)
$ git push origin branch02
Total 0 (delta 0), reused 0 (delta 0), pack-reused 0
remote:
remote: Create a pull request for 'branch02' on GitHub by visiting:
remote: https://github.com/JaeminOh94/branch_project/pull/new/branch02
remote:
To https://github.com/JaeminOh94/branch_project.git
* [new branch] branch02 -> branch02
PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws/branch_project (branch02)
$ git branch
branch01
* branch02
main