Git 기본

ZeroJun·2022년 5월 23일
0

Git

목록 보기
1/1

혼자 작업할 때

- fork한 깃허브 리파지토리를 클론하여 로컬에서 작업하고자 할 때.

(리파지토리 주소 : https://github.com/jyj726/test.git)

// 현재 위치는 클론하고자 하는 directory
git clone https://github.com/jyj726/test.git
또는 // 앞으로 또는 생략
git clone https://github.com/jyj726/test

- local working directory에서 index.js파일을 추가했다. 기존과 변경된 파일들이 어떤 것이 있는지 확인하는 상황.

git status

- local의 index.js를 Staging area로 옮길 때

git add index.js
git add ./index.js
git add .
dit add *

- 내 깃허브 레파지토리에 'index.js수정'이라고 커밋 기록을 남길 때

git commit -m "index.js 수정"
git commit -m 'index.js 수정'

- 커밋한 기록을 되돌려서 이전으로 돌아가고 싶을 때

git reset HEAD~1
git reset HEAD^1
git reset HEAD^

- 커밋한 것을 내 깃허브 origin 리파지토리의 main으로 푸쉬할 때

git push
git push origin main

- 커밋 로그를 확인할 때

git log


함께 작업할 때

- local working directory를 Git의 관리 하에 들어가게 해줄 때

// git init

- origin이라는 이름으로 내 Remote Repository를 등록할 때. (리파지토리 주소 : https://github.com/jyj726/test)

git remote add origin https://github.com/jyj726/test
git remote add origin https://github.com/jyj726/test.git

- 지금까지 main 브랜치에 커밋한 기록을 방금 등록한 origin remote repository에 올려서, 페어에게 코드를 공유하고 싶을 때

git push origin main

- 페어가 내 remote repository를 Fork했을 경우 페어의 remote repository를 내 Local에 pair라는 이름으로 등록하고 싶을 때 (리파지토리 주소 : https://github.com/pair/test)

git remote add pair https://github.com/pair/test.git
git remote add pair https://github.com/pair/test

remote repository의 연결 현황에 대해 알고 싶을 때

git remote --verbose
git remote -v

페어가 작업한 것을 내 Local에 받아오고 싶을 때

git pull pair main
// 특정 commit시점으로부터 각기 다른 commit을 만들면 기본적으로 자동 marge가 된다.

내 Remote Repository에 Local의 내용을 반영할 때

git push origin main

marge시 충돌이 날 경우

터미널에는 아래와 같이 표시된다.

<<<<
console.log('내 변경사항')
=======
console.log('페어의 변경사항')
>>>>
// 여기서 적용할 코드를 선택하면 된다. 페어의 변경사항을 선택하고자 할때는 충돌부분을 아래와 같이 수정해주고 저장하면 된다.
console.log('페어의 변경사항')

// 충돌 해결 후 다시 add
git add *
git add .
git add 수정파일명
git add ./수정파일명

충돌이 해결된 후 staging area에 올라간 파일은 자동으로 commit메세지가 생성된다.

git commit

git push origin main

0개의 댓글