여기서는 누군가가 올려놓은 Remote 서버에 접속해서 Repository를 local로 copy 한 다음에 연동해서 작업하는 연습임.





참고 - README File
• 프로젝트에 대한 설명, 사용방법, 라이센스, 설치방법 등에 대한 내용을 기술하는 파일
• 나, 직장동료, 프로그램 사용자를 위해 존재(자세하게 기재하자)

참고 - .gitignore
• Git 버전 관리에서 제외할 파일목록을 지정하는 파일
• 사용자가 원하지 않는 파일들을 자동으로 commit 대상에서 제외시켜 줌








- Git Clone
앞서 폴더를 만들고
+Git Init 으로 해당 폴더를 초기화 하고
+Remote Repository 를 등록하고
+Remote Repository 의 내용을 Pull 하는 모든 과정을
Git Clone 으로 할수 있음git clone https://github.com/<repository>.git
git clone https://<username>:<token>@github.com/<repository>.git





test_project % cd .. git_ws % git clone https://zerobase:ghp_yazM0qurHSashbS7wVeQcBEJQPRX3Mgzus @github.com /zerobasegit/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 Unpacking objects: 100% (4/4), done.

git_ws % ls test_project HelloGit git_ws % cd HelloGit HelloGit % ls -all total 16 drwxr-xr-x 5 nomaefg staff 160 Nov 6 03:59 . drwxr-xr-x 6 nomaefg staff 192 Nov 6 03:59 .. drwxr-xr-x 13 nomaefg staff 416 Nov 6 03:59 .git -rw-r--r-- 1 nomaefg staff 1799 Nov 6 03:59 .gitignore -rw-r--r-- 1 nomaefg staff 10 Nov 6 03:59 README.md
git branch
HelloGit % git branch * main # * 은 현재 위치를 나타냄 * main : 현재 main에 위치하고 있다는 뜻

git branch -r
HelloGit % git branch -r remotes/origin/HEAD -> origin/main remotes/origin/main

git branch -a
HelloGit % git branch -a * main remotes/origin/HEAD -> origin/main remotes/origin/main

git branch <branchname>
HelloGit % git branch branch01 HelloGit % git branch branch01 * main (현재 위치는 main)

git checkout <branchname>
HelloGit % git checkout branch01 Switched to branch 'branch01' HelloGit % git branch * branch01 (현재 위치가 branch01) main
(제일 오른쪽 (master) 도 (branch01)로 바뀌었다)

git checkout -b <branchname>
HelloGit % git checkout -b branch02 Switched to a new branch 'branch02' HelloGit % git branch branch01 * branch02 (현재 위치는 branch02) main
(현재 remote에 push하지 않았으므로 반영되지 않아 main만 있는 상태임)


git push origin <branchname>

HelloGit % git push origin branch01 Total 0 (delta 0), reused 0 (delta 0) remote: remote: Create a pull request for 'branch01' on GitHub by visiting: remote: https://github.com/zerobasegit/HelloGit/pull/new/branch01 remote: To https://github.com/zerobasegit/HelloGit.git * [new branch] branch01 -> branch01 HelloGit % git branch -a branch01 * branch02 main remotes/origin/HEAD -> origin/main remotes/origin/branch01 (remote에 branch01 추가됨) remotes/origin/main

(아래에 보면 main 외에 branch01이 추가되어 있다)



HelloGit % git push origin branch02 Total 0 (delta 0), reused 0 (delta 0) remote: remote: Create a pull request for 'branch02' on GitHub by visiting: remote: https://github.com/zerobasegit/HelloGit/pull/new/branch02 remote: To https://github.com/zerobasegit/HelloGit.git * [new branch] branch02 -> branch02 HelloGit % git branch -a branch01 * branch02 (현재 위치가 branch02) main remotes/origin/HEAD -> origin/main remotes/origin/branch01 remotes/origin/branch02 remotes/origin/main

(아래에 보면 main 외에 branch02가 추가되어 있다)


git branch -d <branchname>

HelloGit % git branch -d branch02 error: Cannot delete branch 'branch02' checked out at '.../git_ws/HelloGit' HelloGit % git checkout main Switched to branch 'main' Your branch is up to date with 'origin/main'.

HelloGit % git branch -d branch02 Deleted branch branch02 (was 5561acc). HelloGit % git branch -a branch01 * main remotes/origin/HEAD -> origin/main remotes/origin/branch01 remotes/origin/branch02 remotes/origin/main


HelloGit % git branch -d branch01 Deleted branch branch01 (was 5561acc). HelloGit % git branch -a * main remotes/origin/HEAD -> origin/main remotes/origin/branch01 remotes/origin/branch02 remotes/origin/main

git push origin --delete <branchname>

HelloGit % git push origin --delete branch02 To https://github.com/zerobasegit/HelloGit.git - [deleted] branch02 HelloGit % git branch -a * main remotes/origin/HEAD -> origin/main remotes/origin/branch01 remotes/origin/main

(branch02 가 사라져있음)



HelloGit % git push origin --delete branch01 To https://github.com/zerobasegit/HelloGit.git - [deleted] branch01 HelloGit % git branch -a * main remotes/origin/HEAD -> origin/main remotes/origin/main

(branch01도 사라짐)


• 이름 : branch_project
• Option : README.md, .gitignore (Python)

• 위치 : git_ws 하위
• 생성 확인


• 이름 : branch01, branch02
• 이동 : branch01
• 확인 : Local Branch 목록 (현재 Branch 위치 - branch01)
• branch02 만들땐 생성+이동까지
(중간에 git branch -d branch02 는 오타임)

• Push : branch01, branch02
• 확인 : Remote Branch 목록, GitHub


• Local Branch 삭제 : branch01
• 확인 : Local Branch 목록 (에러상황 처리 포함)

• main branch 제외
• 확인 : 전체 Branch 목록

• main, HEAD 제외
• 확인 : 전체 Branch 목록 , GitHub


위 글은 제로베이스 데이터 취업 스쿨의 강의자료를 참고하여 작성되었습니다.