해당 글은 제로베이스데이터스쿨 학습자료를 참고하여 작성되었습니다
GIt이 관리하는 3가지 단계로 구성됨
Working Directory(작업공간) - 실제 소스 파일, 생성한 파일들이 존재
Index(Stage) - Staging area(준비영역)의 역할, git add 한 파일들이 존재
HEAD - 최종 확정본, git commit 한 파일들이 존재
해당폴더로 이동
cd
폴더 생성
mkdir
해당 폴더를 Git이 관리(Working Directory로 선언)
git init
해당 폴더내에 존재하는 것 조회
ls
숨김파일 포함 조회
ls -all
git의 현 상태 출력: add 또는 commit 대상이 있는지 확인가능
git status
Working_Directory에서 Index(Stage)로 추가
git add filename
Index(Stage)에서 HEAD로 커밋
git commit -m "comment" filename
HPcom@DESKTOP-TJ3L1B9 MINGW64 ~/Documents $ mkdir git_ws HPcom@DESKTOP-TJ3L1B9 MINGW64 ~/Documents $ cd git_ws HPcom@DESKTOP-TJ3L1B9 MINGW64 ~/Documents/git_ws $ mkdir test_project HPcom@DESKTOP-TJ3L1B9 MINGW64 ~/Documents/git_ws $ cd test_project/ HPcom@DESKTOP-TJ3L1B9 MINGW64 ~/Documents/git_ws/test_project $ git init; Initialized empty Git repository in C:/Users/HPcom/Documents/git_ws/test_project/.git/ HPcom@DESKTOP-TJ3L1B9 MINGW64 ~/Documents/git_ws/test_project (master) $ ls -all total 4 drwxr-xr-x 1 HPcom 197121 0 Feb 21 15:39 ./ drwxr-xr-x 1 HPcom 197121 0 Feb 21 15:39 ../ drwxr-xr-x 1 HPcom 197121 0 Feb 21 15:39 .git/ HPcom@DESKTOP-TJ3L1B9 MINGW64 ~/Documents/git_ws/test_project (master) $ touch test.txt HPcom@DESKTOP-TJ3L1B9 MINGW64 ~/Documents/git_ws/test_project (master) $ ls test.txt HPcom@DESKTOP-TJ3L1B9 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) HPcom@DESKTOP-TJ3L1B9 MINGW64 ~/Documents/git_ws/test_project (master) $ git add test.txt HPcom@DESKTOP-TJ3L1B9 MINGW64 ~/Documents/git_ws/test_project (master) $ git status On branch master No commits yet Changes to be committed: (use "git rm --cached <file>..." to unstage) new file: test.txt HPcom@DESKTOP-TJ3L1B9 MINGW64 ~/Documents/git_ws/test_project (master) $ git commit -m "first commit" test.txt [master (root-commit) 413203f] first commit 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 test.txt HPcom@DESKTOP-TJ3L1B9 MINGW64 ~/Documents/git_ws/test_project (master) $ git status; On branch master nothing to commit, working tree clean
깃허브 로그인
"Create repository" 클릭
git remote add origin https://<username>:<token>@github.com/<repository>.git
git remote -v
git bash 복사하기 : ctrl insert
git bash 붙여넣기 : shift insert
test_project 연결하기
g@DESKTOP-VO6Q7TM MINGW64 ~/Desktop/ZeroBase/ds_study/git_Ws/test_project (master) $ git remote add origin https://InSung-Na:TOEKNCODE@github.com/InSung-Na/test_project.git
- Remote Repository 정보확인
g@DESKTOP-VO6Q7TM MINGW64 ~/Desktop/ZeroBase/ds_study/git_Ws/test_project (master) $ git remote -v origin https://InSung-Na:TOEKNCODE@github.com/InSung-Na/test_project.git (fetch) origin https://InSung-Na:TOEKNCODE@github.com/InSung-Na/test_project.git (push)
git push origin <branchname>
- Local의 commit한 test.txt를 Remote에 push하기
HPcom@DESKTOP-TJ3L1B9 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), 212 bytes | 212.00 KiB/s, done. Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 To https://github.com/InSung-Na/test_project.git * [new branch] master -> master
git pull origin <branchname>
- Remote에서 README.md를 만들고 Local로 pull하기
HPcom@DESKTOP-TJ3L1B9 MINGW64 ~/Documents/git_ws/test_project (master) $ git pull origin master remote: Enumerating objects: 4, done. remote: Counting objects: 100% (4/4), 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), 669 bytes | 47.00 KiB/s, done. From https://github.com/InSung-Na/test_project * branch master -> FETCH_HEAD 413203f..67e73dc master -> origin/master Updating 413203f..67e73dc Fast-forward README.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 README.md HPcom@DESKTOP-TJ3L1B9 MINGW64 ~/Documents/git_ws/test_project (master) $ ls README.md test.txt
프로젝트에 대한 설명, 사용방법, 라이센스, 설치방법 등에 대한 내용을 기술하는 파일
프로그램 사용자(협업)를 위해 존재
Git 버전 관리에서 제외할 파일을 지정하는 파일
사용자가 원하지 않는 파일들을 자동으로 commit 대상에서 제외시켜 줌
README file, .gitignore-Python 설정 후 생성
master : 로컬에서 만든 Git를 remote에 등록하면 master로 표기됨
main : 깃허브에서 만든 git은 main으로 표기됨
※주의 : 이미 사용중인 다른 사람들에게도 영향을 끼칠 수 있음, 팀원과 합의 후 진행할 것
사용자메뉴 -> settings -> Repositories
수정 후 Update 클릭
git clone https://github.com/<repository>.git
- HelloGit을 git clone 하기
HPcom@DESKTOP-TJ3L1B9 MINGW64 ~/Documents/git_ws $ git clone https://InSung-Na:TOKEN@github.com/InSung-Na/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. HPcom@DESKTOP-TJ3L1B9 MINGW64 ~/Documents/git_ws $ ls HelloGit/ exam_project/ test_project/ HPcom@DESKTOP-TJ3L1B9 MINGW64 ~/Documents/git_ws $ cd HelloGit/ HPcom@DESKTOP-TJ3L1B9 MINGW64 ~/Documents/git_ws/HelloGit (master) $ ls -all total 9 drwxr-xr-x 1 HPcom 197121 0 Feb 21 17:42 ./ drwxr-xr-x 1 HPcom 197121 0 Feb 21 17:42 ../ drwxr-xr-x 1 HPcom 197121 0 Feb 21 17:42 .git/ -rw-r--r-- 1 HPcom 197121 1928 Feb 21 17:42 .gitignore -rw-r--r-- 1 HPcom 197121 10 Feb 21 17:42 README.md
git branch
- Local branch 조회
HPcom@DESKTOP-TJ3L1B9 MINGW64 ~/Documents/git_ws/HelloGit (master) $ git branch * master
git branch -r
- Remote branch 조회
HPcom@DESKTOP-TJ3L1B9 MINGW64 ~/Documents/git_ws/HelloGit (master) $ git branch -r origin/HEAD -> origin/master origin/master
git branch -a
- Local&Remote branch 조회
HPcom@DESKTOP-TJ3L1B9 MINGW64 ~/Documents/git_ws/HelloGit (master) $ git branch -a * master remotes/origin/HEAD -> origin/master remotes/origin/master
git branch branchname
- Local branch 생성
HPcom@DESKTOP-TJ3L1B9 MINGW64 ~/Documents/git_ws/HelloGit (master) $ git branch branch01 HPcom@DESKTOP-TJ3L1B9 MINGW64 ~/Documents/git_ws/HelloGit (master) $ git branch branch01 * master
git checkout branchname
- branch 이동
HPcom@DESKTOP-TJ3L1B9 MINGW64 ~/Documents/git_ws/HelloGit (master) $ git checkout branch01 Switched to branch 'branch01' HPcom@DESKTOP-TJ3L1B9 MINGW64 ~/Documents/git_ws/HelloGit (branch01) $ git branch * branch01 master
git checkout -b branchname
- branch 생성&이동
HPcom@DESKTOP-TJ3L1B9 MINGW64 ~/Documents/git_ws/HelloGit (branch01) $ git checkout -b branch02 Switched to a new branch 'branch02' HPcom@DESKTOP-TJ3L1B9 MINGW64 ~/Documents/git_ws/HelloGit (branch02) $ git branch branch01 * branch02 master
git push origin branchname
- local branch를 remote에 push
HPcom@DESKTOP-TJ3L1B9 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/InSung-Na/HelloGit/pull/new/branch01 remote: To https://github.com/InSung-Na/HelloGit.git * [new branch] branch01 -> branch01 HPcom@DESKTOP-TJ3L1B9 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/InSung-Na/HelloGit/pull/new/branch02 remote: To https://github.com/InSung-Na/HelloGit.git * [new branch] branch02 -> branch02 HPcom@DESKTOP-TJ3L1B9 MINGW64 ~/Documents/git_ws/HelloGit (branch02) $ git branch -a branch01 * branch02 master remotes/origin/HEAD -> origin/master remotes/origin/branch01 remotes/origin/branch02 remotes/origin/master
git branch -d branchname
- branch 삭제하기
HPcom@DESKTOP-TJ3L1B9 MINGW64 ~/Documents/git_ws/HelloGit (branch02) $ git checkout master Switched to branch 'master' Your branch is up to date with 'origin/master'. HPcom@DESKTOP-TJ3L1B9 MINGW64 ~/Documents/git_ws/HelloGit (master) $ git branch -d branch02 Deleted branch branch02 (was c96194c). HPcom@DESKTOP-TJ3L1B9 MINGW64 ~/Documents/git_ws/HelloGit (master) $ git branch -d branch01 Deleted branch branch01 (was c96194c). HPcom@DESKTOP-TJ3L1B9 MINGW64 ~/Documents/git_ws/HelloGit (master) $ git branch * master
git push origin --delete branchname
- Remote branch 삭제하기
HPcom@DESKTOP-TJ3L1B9 MINGW64 ~/Documents/git_ws/HelloGit (master) $ git push origin --delete --delete branch02 To https://github.com/InSung-Na/HelloGit.git - [deleted] branch02 HPcom@DESKTOP-TJ3L1B9 MINGW64 ~/Documents/git_ws/HelloGit (master) $ git push origin --delete --delete branch01 To https://github.com/InSung-Na/HelloGit.git - [deleted] branch01 HPcom@DESKTOP-TJ3L1B9 MINGW64 ~/Documents/git_ws/HelloGit (master) $ git branch -a * master remotes/origin/HEAD -> origin/master remotes/origin/master