<이전글>

2020/12/03 - [IT/Git] - [Git] Git 원격 저장소 여러개 연결

 

[Git] Git 원격 저장소 여러개 연결

한 프로젝트를 깃랩과 깃허브 두 곳에 push하고 싶어서 알아봤다. 현재 로컬 저장소인 Mini_WAS 폴더와 깃랩 원격 저장소와 연결되어있다. 이제 내 깃허브 원격 저장소와도 연결하고 싶어서 과정을

song-yujin.tistory.com

 

1. git 연결 끊기


git 연결 끊기
git remote remove origin

 

git init 취소
rm -r .git

 

 현재 연결되어있는 저장소 경로 보기
git remote -v

 

 

2. 새로운 로컬 저장소 연결

깃랩에 있는 Mini_WAS 저장소와 새롭게 연결하고 싶은 로컬 저장소를 연결하려고 한다.

 

새로 연결하고 싶은 원격 저장소명과 URL 
git remote add "저장소명" "url"

 

그런데!!

이전 글을 참고해서 git push origin master과 git push origin +master 둘 다 해봤는데 아래처럼 표시가 되었다.

$ git push origin master
To http://~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'http://gitlab-intern.polloud.com/songij4/mini_was.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.

~~~~@~~~ MINGW64 ~/eclipse-workspace/Mini_WAS2 (master)
$ git push origin +master
Enumerating objects: 87, done.
Counting objects: 100% (87/87), done.
Delta compression using up to 4 threads
Compressing objects: 100% (77/77), done.
Writing objects: 100% (87/87), 38.01 KiB | 2.38 MiB/s, done.
Total 87 (delta 12), reused 0 (delta 0), pack-reused 0
remote: GitLab: You are not allowed to force push code to a protected branch on this project.
To http://gitlab-intern.polloud.com/songij4/mini_was.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'http://gitlab-intern.polloud.com/songij4/mini_was.git'

 

원인

 

깃랩은 저장소를 생성하면 기본설정이 '관리자(Maintainers)'만 수정 가능하다.

'개발자(Developers)'는 푸시 허용이 돼 있지 않아서 나는 오류이다.

 

 

해결 방법

 

깃랩 레파지토리에서 > settings > Repository > Protected Branches > 선택하는 부분에 Developers + Maintainers 해주면 된다. 

그리고 다시 git push origin +master 해주면 잘 된다!

'IT > Git' 카테고리의 다른 글

[Git] Git 원격 저장소 여러개 연결  (0) 2020.12.03
[Git]git branch 실습  (0) 2020.11.16

한 프로젝트를 깃랩과 깃허브 두 곳에 push하고 싶어서 알아봤다.

 

현재 로컬 저장소인 Mini_WAS 폴더깃랩 원격 저장소와 연결되어있다. 

이제 내 깃허브 원격 저장소와도 연결하고 싶어서 과정을 기록하려고 한다.

 

새로 연결하고 싶은 원격 저장소명과 URL 
git remote add "저장소명" "url"

 

원격 저장소 목록 확인
git remote -v

 

 

origin(깃랩)으로 push와 저장소명(깃허브)으로 push
git push origin master 
git push 저장소명 master
//ex) git push Mini_WAS master

 

origin(깃랩)으로 pull와 저장소명(깃허브)으로 pull
git pull origin master
git pull 저장소명 master

 

 

그런데!

 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'http://gitlab-intern.polloud.com/songij4/mini_was.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.

push 하려고 하니까 이런식으로 에러가 떴다.

git pull을 해줬는데도 안됐다. 그래서 구글링 해봤다.

 

 

원인

 

원인은 .gitignore 파일 또는 README.md 파일로 인해 발생한다고 한다.

 

해결 방법

 

master 앞에 +를 붙이기
git push origin +master

 

 

 

'IT > Git' 카테고리의 다른 글

[Git] git 연결 끊기 & 새로운 로컬 저장소 연결  (0) 2020.12.14
[Git]git branch 실습  (0) 2020.11.16

+ Recent posts