반응형
코딩애플 온라인 강좌 - 개발자도 단기완성!
단연 NO1 강사님의 NO.1 강의 역시나 명강입니다. IT 업계의 대치동 NO1. 강사같은 엄청난 강의력. 코딩애플님의 강의는, 엄청나게 기초적인 것부터 가르치는 듯 보이지만, 실제로 다루는 깊이는 절
codingapple.com
01. 팀원들과 협업
1) 새잡업 폴더 생성
2) git clone 하기
3) git pull 후 git push 하기
① 팀원이 git push 시 주의점
- 먼저 팀원의 깃허브 아이디 필요
- 공동작업자 (Collaborators) 탭에서 등록되어야 push 가능해짐
② 팀원이 먼저 git push 하고 난 후 내가 git push하면? 에러남
git push -u <원격저장소주소> <올릴"로컬"브랜치명>
git push -u https://github.com/jaeheela/github-practice.git main
## 간단해짐
git push -u origin main
## (참고) 실은 -u는 방금 입력한 주소를 기억하라는 뜻
## -u 붙여서 1번 했었으면 나중엔 git push 까지만 입력해도 알아서 잘됨
## 진짜로 git push만 해보셈
## 더 간단해짐 (https://github.com/jaeheela/github-practice.git main에 올려라)
git push
- 원격 vs 로컬 내용이 다르다면 로컬저장소에서 git push가 안됨
- 왜냐면 그런 상황에서 대충 git push 해버리면 코드가 꼬이기 때문에 얘가 미리 예방해주는 것일 뿐
- 원격저장소 최신내용이 로컬저장소에 있을 때만 git push 가능해짐
git pull 원격저장소주소
git pull origin
## 특정 브랜치 fetch + merge
## git pull = git fetch + git merge 축약어
## git fetch : 원격저장소에 있는 commit 중에 로컬에 없는 신규 commit을 가져오라
## git merge : 그걸 merge 하라
git pull origin 특정브랜치명
## (참고)
## git pull 원격저장소주소 브랜치명 입력하면 특정 브랜치만 가져올 수 있음
## origin이라는 변수명을 등록해놨으면 당연히 사용가능
## 예전에 -u 했었으면 git pull, git push까지만 입력해도 잘됨
##1.
## [pull] 받을 게 있나?? 확인하기하기 위해 깃허브에서 내 파일까지 가져옴
## base) jaeheela@Jaehees-MacBook-Air git-practice % git fetch
## gremote: Enumerating objects: 5, done.
## remote: Counting objects: 100% (5/5), done.
## remote: Compressing objects: 100% (3/3), done.
## remote: Total 3 (delta 0), reused 3 (delta 0), pack-reused 0
## Unpacking objects: 100% (3/3), 352 bytes | 117.00 KiB/s, done.
## From https://github.com/jaeheela/github-practice
## 4bef427..760e0c9 main -> origin/main
##2.
## 그리고 상태를 물으면~
## 너의 로컬 브랜치는 원격 origin main에 커밋 하나가 뒤쳐지고 있다는 명령이 뜸
## 즉, 깃허브 레파지토리에서 pull받아야 함
## (base) jaeheela@Jaehees-MacBook-Air git-practice % git status
## On branch main
##
## Your branch is behind 'origin/main' by 1 commit, and can be fast-forwarded.
## (use "git pull" to update your local branch)
##
## 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: cat
##
## no changes added to commit (use "git add" and/or "git commit -a")
- 그래서 git pull 할 때 팀원 2명이서 같은 파일을 건드리고 있을 경우 merge conflict가 날 수 있음
- conflict는 branch 다룰 때 다뤄봤으니 알아서 해결하기
③ 결론 : 협업시 git push 하기 전에 뭐라그러면 git pull 열심히 하기
02. 원격저장소 브랜치 업로드하기
1) 직접 github에서 원격브랜치 생성
2) 로컬에서 만든 브랜치 올리면 원격브랜치 생성
① 로컬에서 원격 브랜치 만들기
##로컬 브런치 생성과 동시에 브런치로 넘어가 작업 가능
(base) jaeheela@Jaehees-MacBook-Air git-practice % git checkout -b my-idea
Switched to a new branch 'my-idea'
## 혹은
git branch my-idea
git switch my-idea
git add
git commit -m '내 아이디어임'
② 작업한 브랜치를 원격 저장소에 같은 이름의 브랜치로 push하기
##그럼 원격 저장소에 올릴게!
##근데 메인브런치 말고 내 이름의 브런치로 따로 생성해서 올려야겠어
git push 원격저장소주소 로컬브랜치명
git push origin my-idea
##내 브런치 보여줘
(base) jaeheela@Jaehees-MacBook-Air github-practice % git branch
main
* my-idea
##깃에 묻을거 있나?
(base) jaeheela@Jaehees-MacBook-Air github-practice % git status
On branch my-idea
nothing to commit, working tree clean
##그럼 원격 저장소에 올릴게!
##근데 메인브런치 말고 내 이름의 브런치로 따로 생성해서 올려야겠어
(base) jaeheela@Jaehees-MacBook-Air github-practice % git push origin my-idea
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), 276 bytes | 276.00 KiB/s, done.
Total 3 (delta 1), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (1/1), completed with 1 local object.
remote:
remote: Create a pull request for 'my-idea' on GitHub by visiting:
remote: https://github.com/jaeheela/github-practice/pull/new/my-idea
remote:
To https://github.com/jaeheela/github-practice.git
* [new branch] my-idea -> my-idea
③ 원격저장소에서 my-idea 브랜치 업로드 된 것 확인 가능
03. 원격브랜치 다운받아 개발하기
① 원격 저장소에 있는 모든 브런치 확인하기
##로컬 브런치 보여줘
(base) jaeheela@Jaehees-MacBook-Air git-practice % git branch
main
* my-idea
##원격 저장소에 올라온 브런치까지 합쳐 보여줘
(base) jaeheela@Jaehees-MacBook-Air git-practice % git branch -a
main
* my-idea
remotes/origin/main
##원격 저장소의 최신 소식 정보를 다 땡겨 받을게!!!
(base) jaeheela@Jaehees-MacBook-Air git-practice % git fetch
remote: Enumerating objects: 4, done.
remote: Counting objects: 100% (4/4), done.
remote: Compressing objects: 100% (1/1), done.
remote: Total 3 (delta 1), reused 3 (delta 1), pack-reused 0
Unpacking objects: 100% (3/3), 256 bytes | 85.00 KiB/s, done.
From https://github.com/jaeheela/github-practice
* [new branch] my-idea -> origin/my-idea
##다시 원격 저장소에 올라온 브런치까지 합쳐 보여줘
(base) jaeheela@Jaehees-MacBook-Air git-practice % git branch -a
main
* my-idea
remotes/origin/main
remotes/origin/my-idea
② 남이 개발한 브런치 다운받기
## 원격저장소인 origin에 [my-idea] 브런치를 가져와
## 나의 로컬 저장소에 [yours-idea] 브런치로 새로 만들어서 checkout 할게요!
(base) jaeheela@Jaehees-MacBook-Air git-practice % git checkout -b yours-idea origin/my-idea
branch 'yours-idea' set up to track 'origin/my-idea'.
Switched to a new branch 'yours-idea'
③ 원격 저장소의 브런치 삭제하기
##origin 원격 저장소의 my-idea 브런치 삭제해줘
(base) jaeheela@Jaehees-MacBook-Air git-practice % git push -d origin my-idea
To https://github.com/jaeheela/github-practice.git
- [deleted] my-idea
##branch 모두 보여줘 [내 로컬브런치 + 원격브런치]
(base) jaeheela@Jaehees-MacBook-Air git-practice % git branch -a
* main
remotes/origin/main
04. Pull request 받기
1) create a merge commit
2) squash and merge
3) rebase and merge
반응형
'git' 카테고리의 다른 글
[git] 10. 원격저장소(GITHUB) 기초 사용법 (git push, git remote, git clone, .gitignore) (0) | 2024.07.07 |
---|---|
[git] 9. GIT 명령어 없이 이클립스(IDE)만 이용해 소스코드를 GITHUB에 업로드하는 법 (0) | 2024.07.07 |
[git] 8. GIT 파일 복구 (git restore, git revert, git reset) (0) | 2024.07.07 |
[git] 7. GIT 브랜치 병합 (git rebase, git merge --squash) (0) | 2024.07.07 |
[git] 6. GIT 브랜치 (git branch, git switch, git log, git merge, git merge -d) (0) | 2024.07.07 |