티스토리 뷰
리포지토리 새로 생성하고 프로젝트를 main 브랜치에 올리려고 한다.
인종차별 문제로 기본 브랜치가 master에서 main으로 바뀌었다고 해서, 기본 브랜치를 main으로 사용하려고 했는데
1.git push
git push origin main
푸쉬하려는데
error: src refspec main does not match any
error: failed to push some refs to 'https://github.com/~~~'
??
뭔가 이상하다.
리포지토리에서 확인하면 mian 브랜치 밖에 없는데,
터미널에서는 master 브랜치 밖에 확인되지 않는다.
(참고로 브랜치 관련해서 아무것도 건들지 않았고 git init만 했음.)
이럴 때는 로컬의 master 브랜치의 이름을 main으로 변경해 주면 된다.
브랜치 이름을 변경해 주는 -m 옵션을 사용한다.
git branch -m [기존 이름] [바꾸고 싶은 이름]
git branch -m master main
2..DS_Store 파일 삭제(Mac에서만)
커밋하고 푸쉬하려고 하다보면 상당히 거슬리는 파일이 나온다.
계속 git add . 하고 commit해도 DS_Store 파일이 계속 변경 되는 건지 몰라도 이 놈때문에 뭘 할 수가 없다..
pull을 하면 이런 메시지를 볼 수 있다.
error: please commit or stash them.
나 방금 커밋 했는디...?
git status 찍어보면
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: .DS_Store
.DS_Store가 변경되었다고 나온다.
찾아보니까 삭제해도 된다고 해서 삭제하기로 결정.
find . -name .DS_Store -print0 | xargs -0 git rm --ignore-unmatch -f
삭제 명령어를 치면 DS_Store 파일이 삭제된 것을 확인할 수 있다.
다시 git status를 찍어보면
Untracked filed이라고 한다. 추적하지 않으므로 삭제한다.
원하는 파일만 삭제되는 건지 한번 확인 후 삭제해준다.
git clean -f --dry-run
git clean -f
삭제 완료!
3.git pull
브랜치 이름도 main으로 변경하고 DS_Store도 삭제했다.
그리고 다시 push 하면?
! [rejected] main -> main (fetch first)
error: failed to push some refs to ~~
ㅋㅋㅋㅋㅋㅋ 또 안된다.
hint: Updates were rejected because the remote contains work that you do not have locally.
This is usually caused by another repository pushing to the same ref.
You may want to first integrate the remote changes (e.g., 'git pull ...') before pushing again.
See the 'Note about fast-forwards' in 'git push --help' for details.
이 에러가 뜨는 이유는 처음 리포지토리 생성할 때 readme와 git ignore 파일을 생성하도록 했기 때문이다.
로컬저장소에는 이 두 파일이 없는데 원격저장소에는 있기 때문.
원격저장소에 있는 readme와 ignore파일을 pull로 가져와서 두 저장소의 상태를 똑같이 맞춰줘야 한다.
git pull origin main 시도.
fatal: refusing to merge unrelated histories
ㅋ.
왜 안되냐하면
원격 저장소는 이 두 파일을 생성하는 커밋을 가지고 있고, 내 로컬저장소는 이 두 파일을 생성하는 커밋이 없기 때문.
즉 같은 부모노드? 를 바라보고 있지 않기 때문에 안되는 것이다.
이럴땐 강제로 pull해서 원격저장소의 파일들을 로컬로 가져와야 한다.
git pull origin main --rebase
기존 프로젝트가 변경되거나 삭제되는 거 없이 두 파일만 로컬로 fetch된다.
성공!
4.git push
이제 git push까지 해보면 잘 된다!!
[참고]
https://wooono.tistory.com/251
[GitHub] .DS_Store 파일 개념 및 삭제 방법
.DS_Store 파일이란? DS_STORE 파일이란 Desktop Services Store의 약자로, 애플에서 정의한 파일 포맷이다. 애플의 맥 OS X 시스템이 finder로 폴더에 접근할 때 자동으로 생기는 파일로써, 해당 폴더에 대한
wooono.tistory.com
https://blog.outsider.ne.kr/1164
git이 추적하지 않는 untracked files 한꺼번에 삭제하기 :: Outsider's Dev Story
git으로 프로젝트를 관리하다 보면 untracked 파일이 쌓이는 경우가 종종 있다.(나만 그럴지도...) 저장소에 넣을 파일은 아니지만, 테스트용으로 로컬에서 임시로 만들었다거나 이미지 등의 파일을
blog.outsider.ne.kr
https://kyeoneee.tistory.com/72
[Github] Default 브랜치명 변경 (master -> main)
Github의 Black lives matter 심심해서 Github 공식 블로그를 구경하다가 10월을 기점으로 Github에서 Repository를 생성할 때 Default 브랜치명이 master에서 main으로 바뀐다는 글을 보았다. (github.blog/chan..
kyeoneee.tistory.com
git push, pull (fatal: refusing to merge unrelated histories) 에러
원격 저장소를 remote로 설정하고 바로 push를 하면 몇가지 오류가 발생할 수도 있다. 예를 들어 아래와 같은 오류 메시지이다. 1 2 ! [rejected] master -> master (non-fast-forward) error: failed to push som..
jobc.tistory.com
- Total
- Today
- Yesterday
- 장고
- ios mvvm
- property wrapper
- sileo
- 백준
- Widget
- New Group
- 백준 4673 swift
- django
- main branch
- 클로저
- readme ignore파일 포함한 repository
- provisioning key
- 애플 인증
- New Group Without Folder
- Xcode
- SWiFT
- 프로퍼티 래퍼
- 이분탐색
- 알고리즘
- xcsharedata
- 백준알고리즘
- palera1n
- 파이썬
- xcuserdata
- 애플 인증서
- closure
- mvvm in swiftui
- 백준 1065번 swift
- ios
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |