본문 바로가기
Git

Mac에서 GitHub 사용법

by jinsuc28 2022. 1. 29.

맥 m1 pro 노트북을 받은 뒤 깃허브 연결 방법을 서치한 결과

밑에 두 블로그에서 큰 도움을 얻을 수 있었다.

 

감사합니다...

 

 

명령어 요약

1. 깃허브 레퍼지토리 만들고 주소 복사

2. git config —global user.name "name", git config —global user.email "깃허브 이메일"

3. 연결 폴더 이동

4. git init

 

<반복 사용하게될 commit 명령어 >

5.

git add . 

git commit -m "메세지" 

git push origin master 

git remote

 

6. git remote -v  (저장소 연결, 안되어 있으면-->) git remote add origin "깃허브 주소"

7. git push origin master

 

 

 

*push 과정에서 github 아이디와 비밀번호를 입력해야함(깃허브 정책이 바뀌어 토큰으로 비밀번호 입력해야함, 두번째 링크 참조)

*명령어 입력시 mac os 보안 문제로 sudo(window으로 얘기하면 관리자권한) 입력해야함

ex)sudo git init

 

https://sin0824.tistory.com/8

 

왕초보! Github 사용법 (Mac os)

개발을 처음 배우면서 가장 어려웠던 건 소스코드를 관리하는 것이었다. 비 전공자였던 나는 구글에 올라와 있는 많은 Github 관련 블로그를 봤지만 도대체 개발자들은 쉬운 말도 왜 어렵게 하는

sin0824.tistory.com

https://hyeo-noo.tistory.com/184

 

[Mac] GitHub push token 오류 해결

Github 오류 7.29일 새벽 갑자기 git push가 안 되는 현상을 겪었다. 오류의 첫 줄이 무슨 말이냐면 Password 인증방식이 일시적으로 brownout(shutdown?)되었다. Password 대신에 personal access token을 사용..

hyeo-noo.tistory.com

https://ifuwanna.tistory.com/263

 

[Git] 원격 저장소 연결 및 끊기 ( git remote )

깃(GIt) 사용시 현재 로컬 저장소(local repository)에 연결되어 있는 원격 저장소(remote repository)를 연결을 끊고 다시 연결 하는 방법을 간단히 포스팅 합니다. 먼저 git remote -v 명령어를 사용하여 현재

ifuwanna.tistory.com

 

git 협업 방법

1. repository git clone

[2. git branch로 push

3. push 요청]

(main에 바로 Push 할 경우)

4. git push 하면 됨

 

아래 pull과 fetch 차이 

-다른 팀원이 올린 것을 가져올 때 소스만 가져오면 fetch

-기존 로컬 파일들과 merge하고 싶으면 pull

https://devlog-wjdrbs96.tistory.com/236

 

[Git] pull과 fetch의 차이는 무엇일까?

pull과 fetch의 차이는 무엇일까? git pull: git remote 명령을 통해 서로 연결된 원격 저장소의 최신 내용을 로컬 저장소로 가져오면서 병합한다. git push의 반대 성격이라 생각하면 된다. git fetch: 로컬

devlog-wjdrbs96.tistory.com

 

git main 과 master 및 오류

기존 master라는 용어가 차별적인 단어로 인식될 수 있는 여지가 있기 때문에 git에서 main을 defalut로 바꾸었다.

 

아래 처럼 git push origin main을 했을 때 오류가 나왔을 경우

기존 repository를 생성할 때 readme를 생성했다면 pull를 한다음에 push해야한다는 오류(반드시.. pull 한다음 프로젝트 진행하자..)

> git push origin main
To https://github.com/jinsuc28/wanted_pre_onboarding_backend.git
 ! [rejected]        main -> main (non-fast-forward)
error: failed to push some refs to 'https://github.com/jinsuc28/wanted_pre_onboarding_backend.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

해결 방법

1. 폴더 새로 생성 다시 clone하고 pull하고 push해서 프로젝트를 다시 생성한다.

(하지만,, 파일위치가 변경되면 곤란한 프로젝트는 불가능한 방법)

2.git push master를 이용한다.

- master branch 생성(master가 아니여도 상관 없음)하고 생성한 브랜치에 push작업을 하고 이를 github 상에서 push &merge를 실행한다. 

- 이를 실행하고 github상에서 push&merge는 문제가 없으나 터미널에서 main에 push를 하면 문제가 생김(터미널은 branch master가 현재 작업 중 브랜치이기 때문에 이를 변경해주어야 한다. 아래 oh my zsh defalut branch 참조)

 

oh my zsh defalut branch 변경하기

oh my zsh 상 master가 기본 branch로 설정된 경우가 많은데

git branch

라는 명령어를 치면

현재 작업이 연결된 브랜치브랜치 목록을 볼 수 있다.

 

 

현재 작업 중브랜치를 변경하려면 

git checkout 브랜치 이름

명령어를 이용하여 변경하자(위 오류 나타나고 pull main은 가능하나 push main가 안되는 이유는 이것)

git checkout main 

'Git' 카테고리의 다른 글

git Conventional Commits  (0) 2022.05.06
git 설치 후 유용한 도구 소개  (0) 2022.05.06
Git과 Github 개념  (0) 2022.05.06
shell 및 Vim command  (0) 2022.05.06