Git 명령어

소이뎁·2023년 2월 14일
0
  • remote repository의 branch와 local repository의 branch는 별개
  • local repository에서 branch 생성 후 remote repository에 push 하면 remote repository에도 branch 생성됨
// git 저장소 생성(디렉토리에 .git 폴더 생성)
git init
// <url>을 디렉토리의 remote repository로 지정
// 기본 remote name = origin
git remote add <remote name> <url>
// <url>을 디렉토리에 복제
git clone <url>
// <remote name> 안의 <branch name>의 변경 사항을 내 디렉토리에 가져와서 merge
// pull은 remote repository가 연결되었을 때 사용
git pull <remote name> <branch name> 
// 변경 내용을 현재 branch에 stage
git add .
// 현재 branch에 commit
git commit -m "#"
// <remote name> 안의 <branch name>에 push
git push <remote name> <branch name>
// remote repository의 모든 branch fetch
git fetch
// or
git fetch <remote name>
  
// <remote name> 안의 <branch name> fetch
git fetch <remote name> <branch name>
// <branch name>을 현재 있는 branch로 merge
git merge <branch name>
// <branch name>의 이름으로 branch 생성
git branch <branch name>
// <branch name>으로 전환
git switch <branch name>
// <branch name>의 이름으로 branch 생성 & 전환
git switch -c <branch name>
// <branch name> 삭제(merge 후에만 사용 가능)
git branch -d <branch name>
// <branch name> 삭제(merge와 관계 없이 사용 가능)
git branch -D <branch name>
// 동일한 명령어
pull = fetch + merge
clone = init + remote add + git pull

0개의 댓글