TIL

5일차_Git 정리(오류 해결하기)

haedal-uni 2021. 9. 17. 22:36
728x90

진행 과정

 

나는 소스트리보다는 Git Bash가 더 편해보여서 Git Bash로 진행을 먼저 했다.

 

git init # Git 저장소 만들기

git init를 입력하니 Reinitialized existing Git repository in 폴더 경로 라는 메세지가 떴다.

 

검색을 해보니 git init 했을 때 Reinitialized existing Git repository in ~ 에러가 뜨면 

git remote -v를 입력하여 원격 remote 주소가 새로 생성한 remote repository 주소인지 확인 한 후

다를 경우 git remote rm orgin으로 삭제하고 다시 새로 추가하면 문제가 해결 된다고 하는데 

나는 git remote -v를 입력하면 아무것도 안뜬다.  ??????

 

 

 

 

 

# git remote -v 입력 후 2줄이 떴는데 아래와 같은 에러가 뜨면 삭제하고 다시 만든다.
git remote rm origin

git remote add origin Repository주소

fatal: 'orgin' does not appear to be a git repository

fatal: Could not read from remote repository.

 

Please make sure you have the correct access rights

and the repository exists.

 

 

 

시작부터 막혀서 소스트리로 진행했다.

소스트리로 test1.py를 push했다.

 

 

이후 다른 폴더에서 git-bash를 다시 진행했다.

소스트리를 진행하고 git remote-v를 실행했더니 이 전에는 아무것도 안떴는데 2줄로 출력되었다.

git status로 현재 상태 확인한 후  git add .으로 파일을 push를 진행했는데 아래와 같은 오류가 떴다.

 

 

To https://github.com ~~git

! [rejected] master -> master (fetch first) error: failed to push some refs to 'https://github.com/~~.git'

hint: Updates were rejected because the remote contains work that you do

hint: not have locally. This is usually caused by another repository pushing

hint: to the same ref. You may want to first integrate the remote changes

hint: (e.g., 'git pull ...') before pushing again.

hint: See the 'Note about fast-forwards' in 'git push --help' for details.

 

 

위 에러 메세지 해결 방법은 구글링을 해보니 2가지 경우인 것 같다.

처음에는 1번으로 진행했다.

 

1. git push origin +master # 강제로 push하기

2. git pull --rebase orgin master

 

깃허브에 들어가보니 소스트리에서 push한 파일은 사라지고 git bash를 통해 push한 파일만 있다.

pull을 하지 않고 강제로 push해서 그런 듯 하다.

 

!!!!! push 하기 전 pull 먼저 하기 !!!!!

 

 

 

 

 

git push 했을 때

 

 

fatal: No configured push destination. ~

라는 메세지가 출력되었다. 현재 위치의 폴더가 깃허브의 원격 Repository와 연결이 안되어있다는 뜻이다.

아래 명령어를 입력하면 된다.

 

git remote add origin Repository주소

 

 

 

 

*

Another git process seems to be running in this repository, e.g. an editor opened by 'git commit'. 

Please make sure all processes are terminated then try again. 

If it still fails, a git process may have crashed in this repository earlier: remove the file manually to continue.

 

일반적으로 두 git명령을 동시에 실행할 때 발생

rm -f .git/index.lock

해결 완료


팀원 저장소에 push하기

 

별칭은 bb로 했다.(보통은 origin으로 설정)

팀원 Repository에 push하려면 내 Repository에 push 하는 것과 다르게 clone을 붙여야 한다.

 

git clone gitRepository주소
git remote add bb gitRepository주소
git add 파일 명
git pull --rebase bb main
git push

 

 

 

push후에 깃허브 사이트에 들어갔더니 내가 push한 파일이 없었다.

 

 

라고 뜨는데 업로드한 걸 보면 아무것도 뜨지 않는다 ... ????????

 

 

 

 

알고보니 팀원분들은 main으로 push가 되었는데 나는 master에 push 되었다. 😂

 

master 대신 main을 기본으로 설정하는 명령어를 아래와 같이 입력하면 된다.

 

 

$ git checkout master # master branch로 이동 

$ git branch -m master main # 로컬에서 master 이름을 main으로 변경

$ git fetch # 서버(Github)에서 최신 커밋을 가져옴

$ git branch --unset-upstream # b/master와 연결 제거 

$ git branch -u bb/main  # bb/main과 연결

$ git symbolic-ref refs/remotes/bb/HEAD refs/remotes/bb/main  
# Default branch를 bb/main으로 업데이트

 


출처: https://dunchi.tistory.com/92 [둔치의 개발이야기]

 


요약

 

폴더 생성 후 폴더 안에 .git 폴더를 생성한다. (만들었는데 없으면 숨겨진 것!!)

 

git init 

git pull ## 중요
git pull origin master 

git add 업로드할 파일

git commit
git commit -m "메모"

git remote -v

git remote add origin 주소입력 # 보낼 곳 등록

git push 
git push origin master

 

 

 

 

처음엔 Github를 잔디심는 용도로 github 사이트 내에서 

왜 이걸 하게 되었고 어떻게 실행을 했으며 중간 에러 해결 과정, 결과를 내는 설명용으로 .md를 만들었었다.

 

그러다보니 명령어를 입력해서 올리는 것은 거의 하지 않아 잘할 수 있을까 걱정이 되었는데

여기 글에 작성한 오류 외에 작성하지 않은 오류까지 계속 접하다보니

오류 해결을 위해 반복적으로 작성하는 명령어는 안보고 입력할 수 있게 되었다;; 😂

728x90