GitHub

Git 명령어 정리

haedal-uni 2021. 9. 26. 00:03
728x90

.git 폴더 생성하기
 

git init 

git pull ## 중요
git pull origin master 

git add 업로드할 파일

git commit
git commit -m "메모"

git remote -v

git remote add origin 주소입력 # 보낼 곳 등록

git push 
git push origin master

 
 

git remote rm origin

git remote add origin Repository주소

 
 

1. git push origin +master # 강제로 push하기

2. git pull --rebase orgin master

 
 


팀원 저장소 PUSH 하기

 

git clone gitRepository주소
git remote add origin gitRepository주소
git add 파일 명
git pull --rebase origin main
git push

 
 
master → main으로 기본 설정하는 명령어 

$ git checkout master # master branch로 이동 

$ git branch -m master main # 로컬에서 master 이름을 main으로 변경

$ git fetch # 서버(Github)에서 최신 커밋을 가져옴

$ git branch --unset-upstream # b/master와 연결 제거 

$ git branch -u bb/main  # bb/main과 연결

$ git symbolic-ref refs/remotes/bb/HEAD refs/remotes/bb/main  
# Default branch를 bb/main으로 업데이트

 
 


branch 생성 후 Merge하기

* 예를 들어 브랜치 명을 coco라고 한다면


브랜치 만들기

git branch coco




브랜치 바꾸기 (main -> coco)

git checkout coco

 
 
병합하기 (main 브랜치에 브랜치 명을 넣기)

git checkout main
git merge coco

git merge --abort  # merge 취소하기



브랜치 삭제하기

git branch -d coco

git branch -D coco # merge하지 않은 branch 강제 삭제



삭제되었는지 브랜치 목록 확인하기

git branch

 

 
 
로컬 저장소에는 삭제했는데 원격저장소에서 삭제가 안될 때

git add -u

를 이용해서 update를 한 후 commit 한다음 push를 진행하기

 
 
커밋 바로 이전으로 되돌아가기

git reset HEAD~1

 

 

The following untracked working tree files would be overwritten by checkout:
에러 시 해결 방법

git clean -d -f

 
 
Merge

git checkout coco  # 브랜치로 이동
git checkout -b coco  # 브랜치 생성 후 해당 브랜치로 이동(이거는 branch 생성하기 전에 같이하는 방법)


git branch -r  # 원격저장소(github) branch 상태 확인
git branch -a  # 로컬저장소(내 컴퓨터) branch 상태 확인

 
 
로컬저장소의 branch (coco)를 github의 branch(remote branch)와 연결(?)

git branch --set-upstream-to orgin/main

 
 
github의 branch에 변경사항이 있을 경우 fetch 명령어를 통해 깃허브의 변경사항을
로컬 저장소로 불러온다.

git fetch

* 깃허브 브랜치(remote branch)에서 변경사항이 있는데 
그 변경사항을 로컬저장소의 브랜치(local branch)의 변경사항과 합치지 않고 
로컬의 작업물을 올릴 경우 충돌이 일어나기 때문이다.
 
 

728x90

'GitHub' 카테고리의 다른 글

Git - changes 파일 없애기, username 변경  (0) 2022.07.09
pr  (0) 2022.06.17