질문 :
팀원들과 함께 협업할 git repository 가 있어. 이 repository 의 정책은 main 을 protection 하고, branch 전략은 Squash & Merge 하는 것으로 설정되어 있어. 이 repository 에서 내가 맡은 부분의 작업을 해보려고 해. 새 branch 를 만들어 이 branch 에서 작업 후, add, commit, push 해서 PR 하는 것 까지의 과정을 하나하나 상세히 설명해줘.
gpt :
좋아! Git repository에서 협업할 때 새 브랜치를 만들고 작업 후 PR(Pull Request)까지 하는 과정을 하나하나 상세히 설명해볼게. 너는 main 브랜치가 보호(protected) 되어 있고, Squash & Merge 전략을 사용 중이라는 설정을 기준으로 설명할게.
git clone 깃레포_주소
main 최신화 및 새 브랜치 생성# git checkout main
git switch main
# git pull origin main
git pull
git checkout -b branch_name
# 변경 사항 확인
git status
# 파일 전체를 staging
git add .
# 또는 선택적으로
git add 파일명
git commit -m "작업 내용"
# git push origin feature/login-form
git push origin branch_name
main, compare는 feature/login-form# git checkout main
git switch main
# git pull origin main
git pull
git branch -D branch_name # 로컬 브랜치 삭제
git push origin --delete branch_name # 원격 브랜치 삭제
git rebase main
git addgit commit --amend 를 통해 최신 commit 덮어쓰기Vim일 때 키보드 조작법i 키를 눌러 입력 모드로 진입ESC 키를 눌러 입력 모드를 빠져나옴:wq 입력 후 Entergit push -f origin branch-name위 a, b, c 과정을 진행하면 내가 수정한 부분이 자동으로 PR에 반영이 되므로,
번거롭게 PR을 close 하고 다시 PR을 진행하는 과정을 하지 않아도 된다.
.gitignore 파일 관리.gitignore 수정.gitignore 파일 열어서 추가:# 예시
*.log
.vscode
# 다른 설정이 있다면 적절한 위치에 추가
# --cached 옵션은 Git 인덱스에서는 삭제하고, 로컬 파일은 삭제하지 않음
git rm --cached *.log
git rm -r --cached .vscode
# add
git add .gitignore
# commit
git commit -m "fix: remove committed .log files and update .gitignore."
git commit -m "fix: remove .vscode directory from repository."
# push
git push origin branch_name
PYTHONPATH=. pytest
git commit
Fix user login bug
- Fixed token expiration issue
- Added proper error handling
- Updated related tests
git commit -m "Update README" -m "Added usage instructions and examples."