유데미 강의를 따라 깃헙데스크탑으로 커밋을 하고 있었는데 결국 깃에 대한 이해가 부족해서 다시 시작하기로 했다. 이해하려고 하지말고 익숙해지는 데 집중해야하나 싶지만, 지금 잘 못 손댔다가 다 꼬여버릴까봐 걱정이 된다. 결국 맥북도 초기화 하고 계정도 초기화 했다. 블로그에 과정을 기록하면서 최대한 꼬이지 않게 차근차근 공부해보고자 한다.
깃헙 레퍼지토리 만들기.
깃을 다운 받기 위해 홈브류(macOS용 패키지 관리자-터미널에서 명령어를 작성하여, 프로그램의 설치, 삭제, 업데이트를 손쉽게 관리) 사용.
1. 홈브류 다운로드
Homebrew
The Missing Package Manager for macOS (or Linux).
brew.sh
1-1 사이트에 있는 스크립트 복사하여 터미널에 붙여넣기 (엔터치고 기다리면 설치 완료됨 homebrew)
[zsh: command not found: brew] 에러를 만났다...
해결 방법 참고 블로그글 3건.
https://designdepot.tistory.com/209
https://javapanda.tistory.com/55
[판다]블로그 글 대로 따라 해봤는데 설치된 홈브루의 버전확인을 해보니 Homebrew 3.3.13-dirty 라고 뜬다. 결국 다시 삭제하고 재설치 했다.
https://ddoongmause.blogspot.com/2021/02/brew.html
🔻나중에 홈브루 공부할 때 참고할만한 사이트.
https://www.44bits.io/ko/keyword/homebrew
https://developsd.tistory.com/126
https://blog.dalso.org/article/m1-mac-homebrew-install
https://velog.io/@susu1991/homebrew-%EC%82%AC%EC%9A%A9%EB%B2%95
https://whitepaek.tistory.com/3
1-2 다운로드한 버전정보 확인
brew --version 명령어를 통해 홈브루가 잘 다운로드 되었는지 확인한다.
Homebrew 3.3.13 가 컴퓨터에 다운로드 되었음을 확인했다.
2. 깃설치
https://git-scm.com/download/mac
Git - Downloading Package
Download for macOS There are several options for installing Git on macOS. Note that any non-source distributions are provided by third parties, and may not be up to date with the latest source release. Homebrew Install homebrew if you don't already have it
git-scm.com
2-1 홈페이지에 나와있는대로
brew install git 명령어를 입력한다.
2-2 다운로드한 버전 정보 확인
git --version 명령어를 통해 확인
git version 2.32.0 (Apple Git-132) 라는 버전이 다운로드 되었다.
3. 깃헙 레퍼지토리 생성 (온라인 저장소 만들기)
3-1 깃헙 계정 생성(가입)
3-2 레퍼지토리 생성
3-3-1 깃헙 데스크탑 설치 - (깃헙 데스크탑 : 깃 명령어를 입력하지 않아도 버튼을 클릭해서 git 명령어를 실행해주는 gui 프로그램)
웹페이지에서 깃헙 데스크탑을 설치 한 후, preference에서 계정을 연동. -> 깃헙서버에 있는 원격 레퍼지토리를 클론을 통해 로컬 저장소로 받아내림 (원하는 작업공간 선택 후 클론.) -> 다운로드된 레퍼지토리를 파인더에서 확인 가능.
4. 깃 초기설정 후 로컬저장소 저장하기
4-1 깃헙 계정 초기설정
git config --global list
git config --global user.name "사용자 이름"
git config --global user.email "깃헙 이메일"
..을 해야하는데 fatal: not in a git directory 오류남. (git repository로 사용하기 위한 초기화 작업이 진행되지 않아 발생하는 오류/현재 폴더에 git에 대한 정보를 담은 파일이 없기 때문에 발생하는 에러라고 함.) (git init 명령어를 통해 초기화 함.- 초기화 및 기본설정 폴더인 .git 디렉토리를 생성하는 명령어 / 디렉토리를 로컬 깃 저장소라고 컴퓨터에게 말해주는 것.)(git init 수행 후 다시 git remote add 명령어 실행하라는 블로그도 있던데 이유를 모르겠음 - 필요 없는 거 같음.) / 나중에 참고할 글 https://www.datree.io/resources/git-error-fatal-not-a-git-repository
Git error - Fatal: Not a git repository and how to fix it | Datree.io
The git error "Fatal: Not a git repository" is among the most common git problem for developers. Learn why it occurs and how to fix it.
www.datree.io
(/Users/b/.git/ 안의 빈 깃 저장소를 다시 초기화했습니다 라고 터미널에 뜨는데 다른 블로그 글을 보니 initialized empty Git repository in [경로] 라고 뜬다고 함.
4-1-2 설정 확인
git config --global user.name
git config --global user.email
4-2 로컬저장소 만들기
여기부터도 잘 모르겠는데.. xcode로 프로젝트를 하나 생성했다. 데스크탑에 b라는 폴더를 만들고 폴더 안에 프로젝트를 저장했다. (프로젝트 디렉토리가 자동생성된다.)
여기서, git init 명령어를 통해 깃헙 로컬지정소를 지정해야하는데 b라는 상위 디렉토리를 지정해야하는지 하위에 생성한 프로젝트 디렉토리를 지정해야하는지 도저히 모르겠다.
cd 명령어를 통해서 결국 하위 디렉토리 폴더에 들어가서 git init 명령어를 입력했다.
<git init>
b@bs-MacBook-Air b % cd OddEvenGame
b@bs-MacBook-Air OddEvenGame % ls
OddEvenGame OddEvenGame.xcodeproj
b@bs-MacBook-Air OddEvenGame % git init
/Users/b/Desktop/b/OddEvenGame/.git/ 안의 기존 깃 저장소를 다시 초기화했습니다
<git status>
b@bs-MacBook-Air OddEvenGame % git status
현재 브랜치 main
커밋하도록 정하지 않은 변경 사항:
(무엇을 커밋할지 바꾸려면 "git add <파일>..."을 사용하십시오)
(use "git restore <file>..." to discard changes in working directory)
수정함: OddEvenGame.xcodeproj/project.pbxproj
커밋할 변경 사항을 추가하지 않았습니다 ("git add" 및/또는 "git commit -a"를
사용하십시오)
<git add>
b@bs-MacBook-Air OddEvenGame % git add
아무 것도 지정하지 않았으므로 아무 것도 추가하지 않습니다.
힌트: Maybe you wanted to say 'git add .'?
힌트: Turn this message off by running
힌트: "git config advice.addEmptyPathspec false"
b@bs-MacBook-Air OddEvenGame % git add .
.을 안찍었더니 아무것도 안추가됨.
<다시 git status>
b@bs-MacBook-Air OddEvenGame % git status
현재 브랜치 main
커밋할 변경 사항:
(use "git restore --staged <file>..." to unstage)
수정함: OddEvenGame.xcodeproj/project.pbxproj
<git commit>
b@bs-MacBook-Air OddEvenGame % git commit -m "Create new project"
[main ecd060d] Create new project
1 file changed, 2 insertions(+), 2 deletions(-)
<git push origin master>
여기서 이거 꼭 해야하는지 모르겠다. 아직 master나 branch는 최대한 건드리고 싶지 않다.
<git remote -v>
해당 명령어를 통해 현재 연결된 저장소가 있는지 확인한다. 연결된 저장소가 없다면 아무 내역도 나오지 않는다.
b@bs-MacBook-Air OddEvenGame % git remote -v
b@bs-MacBook-Air OddEvenGame %
<git remote add origin>
git remote add origin "깃헙 주소" 입력
<다시 git remote -v>
b@bs-MacBook-Air OddEvenGame % git remote add origin https://github.com/barammoon/OddEvenGame.git
b@bs-MacBook-Air OddEvenGame % git remote -v
origin https://github.com/barammoon/OddEvenGame.git (fetch)
origin https://github.com/barammoon/OddEvenGame.git (push)
<git push>
여기에서 두가지 선택사항이 생기는 것 같다.
git push origin master 또는 git push --set-upstream
자세히는 모르겠지만 오리지날 브랜치를 쓸 것인가. 강제로 브랜치를 올릴 것인가... 그런... 차이인 것 같다. 잘 모르겠다. master는 브랜치 이름이라고 한다.
참고. (원격에 브랜치가 없을 때, 브랜치를 만들며 push 하는 법)
https://breakout-theworld.tistory.com/38
b@bs-MacBook-Air OddEvenGame % git push origin master
error: src refspec master does not match any
error: 레퍼런스를 'https://github.com/barammoon/OddEvenGame.git'에 푸시하는데 실패했습니다
또 에러... 우선 해결하기 위해 위의 과정들 반복. git push -u origin main 라고 안해서 그런가...
error: src refspec master does not match any 이 에러는 git에 push할 때, repository 정보가 변경되었을 때 나타나거나 다른곳에서 clone한 repository를 내 repository로 새로 만들어서 push할 때 발생한다고 함.
이때 참고한 블로그 🔻 (git 정보를 초기화하고 원격 repository를 다시 등록 후 push.)
https://skyksit.com/git/git-error-does-not-match/
b@bs-MacBook-Air OddEvenGame % git init
/Users/b/Desktop/b/OddEvenGame/.git/ 안의 기존 깃 저장소를 다시 초기화했습니다
b@bs-MacBook-Air OddEvenGame % git add .
b@bs-MacBook-Air OddEvenGame % git commit -m "Create a new project"
현재 브랜치 main
커밋할 사항 없음, 작업 폴더 깨끗함
b@bs-MacBook-Air OddEvenGame % git remote add origin https://github.com/barammoon/OddEvenGame.git
error: origin 리모트가 이미 있습니다.
b@bs-MacBook-Air OddEvenGame % git push origin master
error: src refspec master does not match any
error: 레퍼런스를 'https://github.com/barammoon/OddEvenGame.git'에 푸시하는데 실패했습니다
b@bs-MacBook-Air OddEvenGame % git push -u origin main
Username for 'https://github.com': barammoon
Password for 'https://barammoon@github.com':
remote: Support for password authentication was removed on August 13, 2021. Please use a personal access token instead.
remote: Please see https://github.blog/2020-12-15-token-authentication-requirements-for-git-operations/ for more information.
fatal: Authentication failed for 'https://github.com/barammoon/OddEvenGame.git/'
git push -u origin main 로 했더니 되는 거 같은데 또 에러..
왜 이러는건지 도대체 모르겠음.
b@bs-MacBook-Air OddEvenGame % git config --global list
error: key does not contain a section: list
아니 아까는 잘 설정된 거 확인했었는데...
해결방법이 여러개인 듯 해서 더 헷갈리고 지친다.
블로그 참고하여 해결 시도 🔻
https://diligentt.tistory.com/7
git 에러 해결 시도 - fatal: Authentication failed for
git 커밋 공부 도중 fatal: Authentication failed for 에러를 만났다. 구글링을 해보는데 발생 원인이 이해가 잘 안되고, 해결 방식이 블로그마다 달라서 직접 포스팅하면서 에러를 해결하기로 했다. [에
diligentt.tistory.com
별로 어려운 문제가 아니었다! 쉽게 해결!
b@bs-MacBook-Air OddEvenGame % git push -u origin main
Username for 'https://github.com': barammoon
Password for 'https://barammoon@github.com':
오브젝트 나열하는 중: 30, 완료.
오브젝트 개수 세는 중: 100% (30/30), 완료.
Delta compression using up to 8 threads
오브젝트 압축하는 중: 100% (26/26), 완료.
오브젝트 쓰는 중: 100% (30/30), 7.91 KiB | 3.96 MiB/s, 완료.
Total 30 (delta 3), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (3/3), done.
To https://github.com/barammoon/OddEvenGame.git
* [new branch] main -> main
branch 'main' set up to track 'origin/main'.
나는 방금 전에 커밋을 완료했는데
왜 4시간 전, 6시간 전에 커밋했다고 뜨는지 모르겠다.
그리고 Initial Commit 이라는 커밋메세지의 커밋을 한 적이 없는데 왜 된 건지 모르겠다. 이상하다 진짜.
성공적인 첫 커밋을 위해 참고한 두개의 블로그 글
1. https://sin0824.tistory.com/8
2. https://sudo-minz.tistory.com/10
+
더 읽어볼 글들 (비슷한 내용들)
3. https://2vup.com/git-first-commit/#-commit-%EC%97%85%EB%A1%9C%EB%93%9C
4. https://dsc-sookmyung.tistory.com/20
7. https://emflant.tistory.com/123
+
git push origin master / git push -u origin main
두개의 명령어의 차이점을 검색해 보았다. 깃의 디폴트 브랜치 이름이 원래는 master였다가 현재는 main으로 변경된 것 같다.
나중에 읽어볼 글 🔻
'git' 카테고리의 다른 글
git 에러 해결 시도 - fatal: Authentication failed for (0) | 2022.02.02 |
---|---|
ssh키.... (0) | 2022.02.01 |