깃허브 다루기

Jes·2022년 6월 16일
0

리모트 설정

첫 리포지토리에 올리려면 리모트 설정을 해줘야한다.

업로드 하려는 폴더 혹은 파일이 있는 저장소 복사해서
터미널창에 cd 저장소 경로 설정후 아래 명령어 입력한다.

git init 1
git add README.md // (업로드할 파일 js파일이면 README.js)
git commit -m "하고싶은말 쓰셈"
git branch -M main  // 기존 master 브랜치에서 main으로 바꿔준다.
git remote add origin git@깃허브계정/리포지토리명
git push -u origin main

리모트 확인

git remote -v

리모트 변경

기존에 설정되있던 리포지토리 remote 제거

git remote remove origin

새 리포지토리 리모트 추가

git remote add origin https://github.com/계정명/리포지토리명

기존에 있던 리모트로 변경시 합쳐줘야 한다.
바로 push origin 해버리면 pull 하라고 에러가 뜬다. 기존에 있던 리모트에 파일과 합쳐서 Push 를 진행 해야한다.

git pull origin branch(설정해놓은 branch)

# brach 확인은  
git branch

create a new repository on the command line

git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin git@github.com:2-phones/-prayer-training-book.git
git push -u origin main

push an existing repository from the command line

git remote add origin git@github.com:2-phones/-prayer-training-book.git
git branch -M main
git push -u origin main

에러 해결

현재 브랜치의 끝이 리모트 브랜치보다 뒤에 있으므로 업데이트가
힌트: 거부되었습니다

// 이 코드로 해결
git push -f origin main

fatal: 정방향이 불가능하므로, 중지합니다.

// 이 코드로 해결
git pull origin branch --rebase

깃허브에 commit push 를 했을대 폴더가 화살표 모양으로 생성되어 들어가지 않는 경우

하위 폴더 와 상위 폴더에 있는 .git 폴더를 삭제후 다시 설정해야한다.

$ rm -rf .git // .git 폴더 삭제명령어
$ git rm --cached . -rf // 변경사항 적용 명령어

위와 같이 코드 작성후 다시 git init 부터, 리모트설정, push 까지 하면 정상적으로 된다.


취소 작업

commit, add, pull, merge 취소하기

add 취소

$ git reset HEAD

commit 취소

$ git reset --hard HEAD

pull 취소

$ git reset --hard ORIG_HEAD

merge 취소

$ git reset --merge ORIG_HEAD

브랜치병합

A 브랜치에 B를 덮어씌우려 할때 A 브랜치로 이동후 -> B 브랜치를 병합시킨다.

$ git checkout A
$ git merge B

profile
Escape Newbie

0개의 댓글